From 594f24d64016005ad58176e2bca9ce57a38751f1 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Mon, 15 May 2023 21:28:45 +0300 Subject: [PATCH] Refactored issues with photo compression (#1300) Added new ways of compression Added photo copy button --- .../com/vk/medianative/MediaImageEncoder.java | 93 ++++ app/src/main/java/com/vtosters/lite/R.java | 156 +++++-- .../lite/downloaders/Multithreading.java | 84 ---- .../ru/vtosters/lite/hooks/PhotoViewer.java | 138 ++++-- .../ru/vtosters/lite/hooks/TogglesHook.java | 5 +- .../lite/ui/fragments/VTSettings.java | 3 +- .../ru/vtosters/lite/utils/Preferences.java | 5 +- smali/res/menu/photo_viewer.xml | 4 + smali/res/values-ru/arrays.xml | 5 + smali/res/values/arrays.xml | 10 + smali/res/values/ids.xml | 1 + smali/res/xml/preferences_media.xml | 12 +- .../vk/medianative/MediaImageEncoder.smali | 432 ------------------ ...EngineProvider$createVkAppConfig$6$1.smali | 19 +- .../im/converters/ImPhotoConverter$a.smali | 4 +- .../upload/UploadCompressStrategy$a2.smali | 4 +- .../lite/upload/l/PhotoUploadTask.smali | 11 +- 17 files changed, 342 insertions(+), 644 deletions(-) create mode 100644 app/src/main/java/com/vk/medianative/MediaImageEncoder.java delete mode 100644 app/src/main/java/ru/vtosters/lite/downloaders/Multithreading.java delete mode 100644 smali/smali_classes3/com/vk/medianative/MediaImageEncoder.smali diff --git a/app/src/main/java/com/vk/medianative/MediaImageEncoder.java b/app/src/main/java/com/vk/medianative/MediaImageEncoder.java new file mode 100644 index 000000000..7bd6ec433 --- /dev/null +++ b/app/src/main/java/com/vk/medianative/MediaImageEncoder.java @@ -0,0 +1,93 @@ +package com.vk.medianative; + +import android.graphics.Bitmap; +import android.graphics.Bitmap.CompressFormat; +import android.os.Build; +import android.util.Log; +import ru.vtosters.lite.utils.Preferences; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +public class MediaImageEncoder { + private static boolean compressBitmap(Bitmap bitmap, File file, CompressFormat format, int quality) { + try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { + return bitmap.compress(format, quality, fileOutputStream); + } catch (IOException e) { + Log.e(MediaImageEncoder.class.getSimpleName(), "Bitmap compression error: " + e); + return false; + } + } + + private static boolean compressBitmapJpeg(Bitmap bitmap, File file, int quality) { + return compressBitmap(bitmap, file, CompressFormat.JPEG, quality); + } + + private static boolean compressBitmapLossless(Bitmap bitmap, File file) { + return compressBitmap(bitmap, file, CompressFormat.PNG, 100); + } + + private static boolean compressBitmapNative(Bitmap bitmap, File file, int quality) { + if (MediaNative.isX86() || MediaNative.isAsus() || Build.VERSION.SDK_INT < 24) { + Log.e(MediaImageEncoder.class.getSimpleName(), "JPEG turbo not supported on this device!"); + return compressBitmapJpeg(bitmap, file, quality); + } + + byte[] jpegData = MediaNative.compressBitmapJpeg(bitmap, quality); + + if (jpegData == null) { + return false; + } + + try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { + fileOutputStream.write(jpegData); + return true; + } catch (IOException e) { + Log.e(MediaImageEncoder.class.getSimpleName(), "JPEG compression error: " + e); + return false; + } + } + + public static boolean encodePicture(Bitmap bitmap, File file, int quality) { + if (bitmap != null && !bitmap.isRecycled() && bitmap.getWidth() * bitmap.getHeight() != 0) { + switch (Preferences.getPreferences().getString("compression", "jpeg")) { + case "skip" -> { + return compressBitmapLossless(bitmap, file); + } + case "jpeg" -> { + return compressBitmapJpeg(bitmap, file, quality); + } + case "native" -> { + return compressBitmapNative(bitmap, file, quality); + } + } + } + + return false; + } + + public static boolean needToSkipCompression() { + return Preferences.getPreferences().getString("compression", "jpeg").equals("skip"); + } + + public static boolean needToCompress() { + return !needToSkipCompression(); + } + + public static boolean encodeJpeg(Bitmap bitmap, File file) { + return encodePicture(bitmap, file, 90); + } + + public static boolean encodeJpegWithoutCompression(Bitmap bitmap, File file) { + return encodePicture(bitmap, file, 95); + } + + public static boolean encodeJpeg(Bitmap bitmap, File file, int quality) { + if (bitmap != null && !bitmap.isRecycled() && bitmap.getWidth() * bitmap.getHeight() != 0) { + return needToCompress() ? compressBitmapNative(bitmap, file, quality) : compressBitmapJpeg(bitmap, file, quality); + } else { + return false; + } + } +} diff --git a/app/src/main/java/com/vtosters/lite/R.java b/app/src/main/java/com/vtosters/lite/R.java index d39ab7a9a..7ba2b6a35 100644 --- a/app/src/main/java/com/vtosters/lite/R.java +++ b/app/src/main/java/com/vtosters/lite/R.java @@ -222,8 +222,10 @@ public final class R { public static final int undel_value = 0x7f030075; // 2130903157 public static final int wallpaper_change_dialog = 0x7f030076; // 2130903158 public static final int accent_select_type = 0x7f030077; // 2130903159 - public static final int theme_type_name = 0x7f030078; // 2130903160 - public static final int theme_type_name_checkbox = 0x7f030079; // 2130903161 + public static final int compression = 0x7f030078; // 2130903160 + public static final int compression_value = 0x7f030079; // 2130903161 + public static final int theme_type_name = 0x7f03007a; // 2130903162 + public static final int theme_type_name_checkbox = 0x7f03007b; // 2130903163 } public static final class attr { @@ -4995,7 +4997,9 @@ public final class R { public static final int $splash__8 = 0x7f080be6; // 2131233766 public static final int $splash__9 = 0x7f080be7; // 2131233767 public static final int checker_background = 0x7f080be8; // 2131233768 - public static final int splash = 0x7f080be9; // 2131233769 + public static final int custom_thumb_selector = 0x7f080be9; // 2131233769 + public static final int custom_track_selector = 0x7f080bea; // 2131233770 + public static final int splash = 0x7f080beb; // 2131233771 public static final int abc_control_background_material = 0x7f080032; // 2131230770 public static final int ic_action_close = 0x7f080322; // 2131231522 public static final int ic_camera_outline_28_new = 0x7f0803a0; // 2131231648 @@ -11054,6 +11058,8 @@ public final class R { public static final int color_name = 0x7f0a1022; // 2131365922 public static final int color_value = 0x7f0a1023; // 2131365923 public static final int color_preview_border = 0x7f0a1024; // 2131365924 + public static final int account_backup_view = 0x7f0a1025; // 2131365925 + public static final int copy_image = 0x7f0a1026; // 2131365926 } public static final class integer { @@ -12993,6 +12999,30 @@ public final class R { public static final int vt_changeable_foreground = 0x7f0f0044; // 2131689540 public static final int vt_launcher = 0x7f0f0045; // 2131689541 public static final int vt_party_foreground = 0x7f0f0047; // 2131689543 + public static final int ic_launcher_balloon_pink = 0x7f0f0048; // 2131689544 + public static final int ic_launcher_balloon_pink_background = 0x7f0f0049; // 2131689545 + public static final int ic_launcher_balloon_pink_foreground = 0x7f0f004a; // 2131689546 + public static final int ic_launcher_bubble_gum = 0x7f0f004b; // 2131689547 + public static final int ic_launcher_bubble_gum_background = 0x7f0f004c; // 2131689548 + public static final int ic_launcher_bubble_gum_foreground = 0x7f0f004d; // 2131689549 + public static final int ic_launcher_comics = 0x7f0f004e; // 2131689550 + public static final int ic_launcher_comics_background = 0x7f0f004f; // 2131689551 + public static final int ic_launcher_comics_foreground = 0x7f0f0050; // 2131689552 + public static final int ic_launcher_flowers = 0x7f0f0051; // 2131689553 + public static final int ic_launcher_flowers_background = 0x7f0f0052; // 2131689554 + public static final int ic_launcher_flowers_foreground = 0x7f0f0053; // 2131689555 + public static final int ic_launcher_metal_dark = 0x7f0f0054; // 2131689556 + public static final int ic_launcher_metal_dark_background = 0x7f0f0055; // 2131689557 + public static final int ic_launcher_metal_dark_foreground = 0x7f0f0056; // 2131689558 + public static final int ic_launcher_pin_blue = 0x7f0f0057; // 2131689559 + public static final int ic_launcher_pin_blue_background = 0x7f0f0058; // 2131689560 + public static final int ic_launcher_pin_blue_foreground = 0x7f0f0059; // 2131689561 + public static final int ic_launcher_rabbit = 0x7f0f005a; // 2131689562 + public static final int ic_launcher_rabbit_background = 0x7f0f005b; // 2131689563 + public static final int ic_launcher_rabbit_foreground = 0x7f0f005c; // 2131689564 + public static final int ic_launcher_shine = 0x7f0f005d; // 2131689565 + public static final int ic_launcher_shine_background = 0x7f0f005e; // 2131689566 + public static final int ic_launcher_shine_foreground = 0x7f0f005f; // 2131689567 public static final int vt_adaptive_launcher_foneground = 0x7f0f0043; // 2131689539 public static final int vt_launcher_round = 0x7f0f0046; // 2131689542 public static final int ic_logo_facebook_28 = 0x7f0f0003; // 2131689475 @@ -19547,49 +19577,82 @@ public final class R { public static final int accent_color_summ = 0x7f12183b; // 2131892283 public static final int accent_color_title = 0x7f12183c; // 2131892284 public static final int accents = 0x7f12183d; // 2131892285 - public static final int add_to_ads_stories_whitelist = 0x7f12183e; // 2131892286 - public static final int amoledtheme_summ = 0x7f12183f; // 2131892287 - public static final int amoledtheme_title = 0x7f121840; // 2131892288 - public static final int app_open_by_default_settings = 0x7f121841; // 2131892289 - public static final int audio_deleted_from_cache = 0x7f121842; // 2131892290 - public static final int blockminiapps_summ = 0x7f121843; // 2131892291 - public static final int blockminiapps_title = 0x7f121844; // 2131892292 - public static final int businessDisabler_title = 0x7f121845; // 2131892293 - public static final int by_choice = 0x7f121846; // 2131892294 - public static final int calls_not_available = 0x7f121847; // 2131892295 - public static final int cannot_write = 0x7f121848; // 2131892296 - public static final int change_accent_color = 0x7f121849; // 2131892297 - public static final int copydebuginfo_summ = 0x7f12184a; // 2131892298 - public static final int copydebuginfo_title = 0x7f12184b; // 2131892299 - public static final int copyownlink_summ = 0x7f12184c; // 2131892300 - public static final int copyownlink_title = 0x7f12184d; // 2131892301 - public static final int crash_service_name = 0x7f12184e; // 2131892302 - public static final int current_theme = 0x7f12184f; // 2131892303 - public static final int custom_links_warning = 0x7f121850; // 2131892304 - public static final int data_updated = 0x7f121851; // 2131892305 - public static final int device_info = 0x7f121852; // 2131892306 - public static final int device_info_copied = 0x7f121853; // 2131892307 - public static final int dialogstats = 0x7f121854; // 2131892308 - public static final int downloading_update = 0x7f121855; // 2131892309 - public static final int invalid_pack_link = 0x7f121856; // 2131892310 - public static final int maxquality_summ = 0x7f121857; // 2131892311 - public static final int maxquality_title = 0x7f121858; // 2131892312 - public static final int monettheme_summ = 0x7f121859; // 2131892313 - public static final int monettheme_title = 0x7f12185a; // 2131892314 - public static final int newsfeed_notif_summ = 0x7f12185b; // 2131892315 - public static final int newsfeed_notif_title = 0x7f12185c; // 2131892316 - public static final int open_bot = 0x7f12185d; // 2131892317 - public static final int promotedstickers_title = 0x7f12185e; // 2131892318 - public static final int remove_from_ads_stories_whitelist = 0x7f12185f; // 2131892319 - public static final int select_color = 0x7f121860; // 2131892320 - public static final int select_palette = 0x7f121861; // 2131892321 - public static final int sources = 0x7f121862; // 2131892322 - public static final int updateverifdata_summ = 0x7f121863; // 2131892323 - public static final int updateverifdata_title = 0x7f121864; // 2131892324 - public static final int useOldAppVer_summ = 0x7f121865; // 2131892325 - public static final int useOldAppVer_title = 0x7f121866; // 2131892326 - public static final int vkx_integration_enabled_info = 0x7f121867; // 2131892327 - public static final int writebar_ios_title = 0x7f121868; // 2131892328 + public static final int accounts_saved_by_path = 0x7f12183e; // 2131892286 + public static final int add_to_ads_stories_whitelist = 0x7f12183f; // 2131892287 + public static final int amoledtheme_summ = 0x7f121840; // 2131892288 + public static final int amoledtheme_title = 0x7f121841; // 2131892289 + public static final int appLanguage = 0x7f121842; // 2131892290 + public static final int app_open_by_default_settings = 0x7f121843; // 2131892291 + public static final int applying_accent = 0x7f121844; // 2131892292 + public static final int audio_deleted_from_cache = 0x7f121845; // 2131892293 + public static final int blockminiapps_summ = 0x7f121846; // 2131892294 + public static final int blockminiapps_title = 0x7f121847; // 2131892295 + public static final int businessDisabler_title = 0x7f121848; // 2131892296 + public static final int by_choice = 0x7f121849; // 2131892297 + public static final int calls_not_available = 0x7f12184a; // 2131892298 + public static final int cannot_write = 0x7f12184b; // 2131892299 + public static final int change_accent_color = 0x7f12184c; // 2131892300 + public static final int copydebuginfo_summ = 0x7f12184d; // 2131892301 + public static final int copydebuginfo_title = 0x7f12184e; // 2131892302 + public static final int copyownlink_summ = 0x7f12184f; // 2131892303 + public static final int copyownlink_title = 0x7f121850; // 2131892304 + public static final int crash_service_name = 0x7f121851; // 2131892305 + public static final int currentLanguage = 0x7f121852; // 2131892306 + public static final int current_theme = 0x7f121853; // 2131892307 + public static final int custom_links_warning = 0x7f121854; // 2131892308 + public static final int data = 0x7f121855; // 2131892309 + public static final int data_updated = 0x7f121856; // 2131892310 + public static final int datasettings_title = 0x7f121857; // 2131892311 + public static final int device_info = 0x7f121858; // 2131892312 + public static final int device_info_copied = 0x7f121859; // 2131892313 + public static final int dialogstats = 0x7f12185a; // 2131892314 + public static final int disable_analytics = 0x7f12185b; // 2131892315 + public static final int disable_analytics_summ = 0x7f12185c; // 2131892316 + public static final int downloading_update = 0x7f12185d; // 2131892317 + public static final int error_applying_accent = 0x7f12185e; // 2131892318 + public static final int error_no_text = 0x7f12185f; // 2131892319 + public static final int error_saving_file = 0x7f121860; // 2131892320 + public static final int failed_to_get_text = 0x7f121861; // 2131892321 + public static final int invalid_pack_link = 0x7f121862; // 2131892322 + public static final int invalidate_theme_cache_title = 0x7f121863; // 2131892323 + public static final int logColors_title = 0x7f121864; // 2131892324 + public static final int maxquality_summ = 0x7f121865; // 2131892325 + public static final int maxquality_title = 0x7f121866; // 2131892326 + public static final int monettheme_summ = 0x7f121867; // 2131892327 + public static final int monettheme_title = 0x7f121868; // 2131892328 + public static final int newsfeed_notif_summ = 0x7f121869; // 2131892329 + public static final int newsfeed_notif_title = 0x7f12186a; // 2131892330 + public static final int open_bot = 0x7f12186b; // 2131892331 + public static final int promotedstickers_title = 0x7f12186c; // 2131892332 + public static final int remove_encryption_key = 0x7f12186d; // 2131892333 + public static final int remove_from_ads_stories_whitelist = 0x7f12186e; // 2131892334 + public static final int reset_accounts = 0x7f12186f; // 2131892335 + public static final int reset_all_settings = 0x7f121870; // 2131892336 + public static final int restore_accounts = 0x7f121871; // 2131892337 + public static final int restore_settings = 0x7f121872; // 2131892338 + public static final int save_accounts = 0x7f121873; // 2131892339 + public static final int save_online_data = 0x7f121874; // 2131892340 + public static final int select_color = 0x7f121875; // 2131892341 + public static final int select_palette = 0x7f121876; // 2131892342 + public static final int sources = 0x7f121877; // 2131892343 + public static final int storiesGroupsAdBlock = 0x7f121878; // 2131892344 + public static final int storiesGroupsAdBlocksummary = 0x7f121879; // 2131892345 + public static final int systemtheme = 0x7f12187a; // 2131892346 + public static final int systemtheme_enabled = 0x7f12187b; // 2131892347 + public static final int systemtheme_summ = 0x7f12187c; // 2131892348 + public static final int updateverifdata_summ = 0x7f12187d; // 2131892349 + public static final int updateverifdata_title = 0x7f12187e; // 2131892350 + public static final int useCustomPrefsStyle_summ = 0x7f12187f; // 2131892351 + public static final int useCustomPrefsStyle_title = 0x7f121880; // 2131892352 + public static final int useGenius_summ = 0x7f121881; // 2131892353 + public static final int useGenius_title = 0x7f121882; // 2131892354 + public static final int useNewColorEngine_summ = 0x7f121883; // 2131892355 + public static final int useNewColorEngine_title = 0x7f121884; // 2131892356 + public static final int useOldAppVer_summ = 0x7f121885; // 2131892357 + public static final int useOldAppVer_title = 0x7f121886; // 2131892358 + public static final int vkx_integration_enabled_info = 0x7f121887; // 2131892359 + public static final int whitelisted_ad_groups_stories_title = 0x7f121888; // 2131892360 + public static final int writebar_ios_title = 0x7f121889; // 2131892361 } public static final class style { @@ -20786,5 +20849,6 @@ public final class R { public static final int preferences_proxy = 0x7f15001c; // 2132082716 public static final int preferences_tgs = 0x7f15001d; // 2132082717 public static final int preferences_themes = 0x7f15001e; // 2132082718 + public static final int locales_config = 0x7f15001f; // 2132082719 } } \ No newline at end of file diff --git a/app/src/main/java/ru/vtosters/lite/downloaders/Multithreading.java b/app/src/main/java/ru/vtosters/lite/downloaders/Multithreading.java deleted file mode 100644 index f07e97f5d..000000000 --- a/app/src/main/java/ru/vtosters/lite/downloaders/Multithreading.java +++ /dev/null @@ -1,84 +0,0 @@ -package ru.vtosters.lite.downloaders; - -import android.util.Log; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.net.HttpURLConnection; -import java.net.URL; - -public class Multithreading { - public static void download(URL url, File f, int threadCount) { - try { - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - int responseCode = connection.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { - int fileSize = connection.getContentLength(); - connection.disconnect(); - RandomAccessFile file = new RandomAccessFile(f, "rw"); - file.setLength(fileSize); - file.close(); - if (threadCount == 0) threadCount = 4; - int partSize = fileSize / threadCount; - DownloadThread[] threads = new DownloadThread[threadCount]; - for (int i = 0; i < threadCount; i++) { - int startByte = i * partSize; - int endByte = (i + 1) * partSize - 1; - if (i == threadCount - 1) { - endByte = fileSize - 1; - } - DownloadThread thread = new DownloadThread(i, url, f.getName(), startByte, endByte); - thread.start(); - threads[i] = thread; - } - for (DownloadThread thread : threads) { - thread.join(); - } - } else { - Log.d("Multithreading", "Error, code: " + responseCode); - } - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - } - - static class DownloadThread extends Thread { - private final int threadId; - private final URL url; - private final String fileName; - private final int startByte; - private final int endByte; - - public DownloadThread(int threadId, URL url, String fileName, int startByte, int endByte) { - this.threadId = threadId; - this.url = url; - this.fileName = fileName; - this.startByte = startByte; - this.endByte = endByte; - } - - @Override - public void run() { - try { - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestProperty("Range", "bytes=" + startByte + "-" + endByte); - InputStream input = connection.getInputStream(); - RandomAccessFile file = new RandomAccessFile(fileName, "rw"); - file.seek(startByte); - byte[] buffer = new byte[1024]; - int length = input.read(buffer); - while (length != -1) { - file.write(buffer, 0, length); - length = input.read(buffer); - } - file.close(); - input.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/ru/vtosters/lite/hooks/PhotoViewer.java b/app/src/main/java/ru/vtosters/lite/hooks/PhotoViewer.java index c896fb9dc..cb61c4b9d 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/PhotoViewer.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/PhotoViewer.java @@ -12,6 +12,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.Toast; import androidx.annotation.Nullable; +import androidx.core.content.FileProvider; import com.vk.core.dialogs.actionspopup.ActionsPopup; import com.vk.core.dialogs.alert.VkAlertDialog; import com.vk.core.ui.themes.VKThemeHelper; @@ -23,6 +24,8 @@ import com.vtosters.lite.R; import com.vtosters.lite.attachments.DocumentAttachment; import com.vtosters.lite.attachments.PhotoAttachment; import okhttp3.*; +import okio.BufferedSink; +import okio.Okio; import org.json.JSONException; import org.json.JSONObject; import ru.vtosters.lite.di.singleton.VtOkHttpClient; @@ -30,6 +33,7 @@ import ru.vtosters.lite.utils.AndroidUtils; import ru.vtosters.lite.utils.LifecycleUtils; import ru.vtosters.lite.utils.Preferences; +import java.io.File; import java.io.IOException; import java.net.URLEncoder; import java.util.List; @@ -37,58 +41,83 @@ import java.util.List; public class PhotoViewer { static OkHttpClient client = VtOkHttpClient.getInstance(); + @SuppressLint("NonConstantResourceId") public static boolean interceptClick(AttachmentWithMedia attachment, MenuItem item, View view) { - if (item.getItemId() == R.id.search_photo) { - if (attachment instanceof PhotoAttachment) { - searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromPhotoAttachment((PhotoAttachment) attachment)); - } else if (attachment instanceof DocumentAttachment) { - var documentAttachment = (DocumentAttachment) attachment; - if (documentAttachment.J != null) - try { - searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromDocumentAttachment(documentAttachment)); - } catch (Exception e) { + switch (item.getItemId()) { + case R.id.copy_image -> { + if (attachment instanceof PhotoAttachment) { + copyImage(getUrlFromPhotoAttachment((PhotoAttachment) attachment), String.valueOf(attachment.getId())); + } else if (attachment instanceof DocumentAttachment) { + var documentAttachment = (DocumentAttachment) attachment; + if (documentAttachment.J != null) + try { + copyImage(getUrlFromDocumentAttachment(documentAttachment), String.valueOf(attachment.getId())); + } catch (Exception e) { + ToastUtils.a(R.string.photo_get_error); + } + else ToastUtils.a(R.string.photo_get_error); - } - else - ToastUtils.a(R.string.photo_get_error); + } + return true; } - return true; - } else if (item.getItemId() == R.id.copy_photo_url) { - if (attachment instanceof PhotoAttachment) { - copyPhotoUrl(getUrlFromPhotoAttachment((PhotoAttachment) attachment)); - } else if (attachment instanceof DocumentAttachment) { - var documentAttachment = (DocumentAttachment) attachment; - if (documentAttachment.J != null) - try { - copyPhotoUrl(getUrlFromDocumentAttachment(documentAttachment)); - } catch (Exception e) { + case R.id.copy_photo_url -> { + if (attachment instanceof PhotoAttachment) { + copyPhotoUrl(getUrlFromPhotoAttachment((PhotoAttachment) attachment)); + } else if (attachment instanceof DocumentAttachment) { + var documentAttachment = (DocumentAttachment) attachment; + if (documentAttachment.J != null) + try { + copyPhotoUrl(getUrlFromDocumentAttachment(documentAttachment)); + } catch (Exception e) { + ToastUtils.a(R.string.photo_get_error); + } + else ToastUtils.a(R.string.photo_get_error); - } - else - ToastUtils.a(R.string.photo_get_error); + } + return true; } - return true; - } else if (item.getItemId() == R.id.open_original_photo) { - if (attachment instanceof PhotoAttachment) { - openUrl(getUrlFromPhotoAttachment((PhotoAttachment) attachment)); - } else if (attachment instanceof DocumentAttachment) { - var documentAttachment = (DocumentAttachment) attachment; - if (documentAttachment.J != null) - try { - openUrl(getUrlFromDocumentAttachment(documentAttachment)); - } catch (Exception e) { + case R.id.open_original_photo -> { + if (attachment instanceof PhotoAttachment) { + openUrl(getUrlFromPhotoAttachment((PhotoAttachment) attachment)); + } else if (attachment instanceof DocumentAttachment) { + var documentAttachment = (DocumentAttachment) attachment; + if (documentAttachment.J != null) + try { + openUrl(getUrlFromDocumentAttachment(documentAttachment)); + } catch (Exception e) { + ToastUtils.a(R.string.photo_get_error); + } + else ToastUtils.a(R.string.photo_get_error); - } - else - ToastUtils.a(R.string.photo_get_error); + } + return true; } - return true; } return true; } @SuppressLint("UseCompatLoadingForDrawables") public static void addMenuItems(AttachmentWithMedia attachment, ActionsPopup.b actionPopup, int i, boolean z) { + actionPopup.a(R.string.copy, + ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_copy_outline_28, VKThemeHelper.g(R.attr.header_tint)), + false, + () -> { + if (attachment instanceof PhotoAttachment) { + copyImage(getUrlFromPhotoAttachment((PhotoAttachment) attachment), String.valueOf(attachment.getId())); + } else if (attachment instanceof DocumentAttachment) { + var documentAttachment = (DocumentAttachment) attachment; + if (documentAttachment.J != null) + try { + copyImage(getUrlFromDocumentAttachment(documentAttachment), String.valueOf(attachment.getId())); + } catch (Exception e) { + ToastUtils.a(R.string.photo_get_error); + } + else + ToastUtils.a(R.string.photo_get_error); + } + return null; + } + ); actionPopup.a(R.string.search_photo_content, ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_menu_search_outline_28, VKThemeHelper.g(R.attr.header_tint)), false, @@ -194,6 +223,37 @@ public class PhotoViewer { } } + private static void copyImage(String link, String name) { + Request request = new Request.a().b(link).a(); + File file = new File(AndroidUtils.getGlobalContext().getExternalCacheDir(), name + ".jpg"); + + if (file.exists()) { + copyImageToClipboard(file); + return; + } + + new Thread() { + @Override + public void run() { + try (Response response = client.a(request).execute()) { + try (BufferedSink sink = Okio.a(Okio.b(file))) { + sink.a(response.a().f()); + } + + copyImageToClipboard(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + }.start(); + } + + private static void copyImageToClipboard(File file) { + Uri path = FileProvider.getUriForFile(AndroidUtils.getGlobalContext(), "com.vtosters.lite.common.VKFileProvider", file); + ClipData clip = ClipData.newUri(AndroidUtils.getGlobalContext().getContentResolver(), "Image", path); + ((ClipboardManager) AndroidUtils.getGlobalContext().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip); + } + private static int selectedEngine() { return Preferences.getPreferences().getInt("search_engine", 0); } diff --git a/app/src/main/java/ru/vtosters/lite/hooks/TogglesHook.java b/app/src/main/java/ru/vtosters/lite/hooks/TogglesHook.java index 2053a4401..35322822d 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/TogglesHook.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/TogglesHook.java @@ -1,5 +1,6 @@ package ru.vtosters.lite.hooks; +import com.vk.medianative.MediaImageEncoder; import com.vk.toggle.FeatureManager; import com.vk.toggle.Features; @@ -8,7 +9,7 @@ import static ru.vtosters.lite.utils.Preferences.*; public class TogglesHook { public static boolean shouldPatch(Features.Type feature) { return switch (feature) { - case AB_IM_LONGPOLL_MSG_BATCHING, FEATURE_MOZJPEG, AB_IM_VIEW_POOL, AB_MULTI_GIFTS, AB_NEWS_VIDEO_LAYOUT_TEXT, AB_STICKERS_DISCOVER, AB_GIFTS_FROM_KEYBOARD, FEATURE_FEED_DEFAULT_LIST_ALWAYS, EXPERIMENT_NEWS_VIDEO_LAYOUT_TEXT, FEATURE_DISCOVER_CATEGORIES, FEATURE_FAVE_PERF_IMPROVE, FEATURE_GROUP_ADMIN_MESSAGES, FEATURE_GROUP_MSG_PUSH_PARAM, FEATURE_IMAGE_QUALITY_UPGRADE, FEATURE_IM_AUDIO_MSG_TRANSCRIPT, FEATURE_IM_CASPER_MSGS, FEATURE_IM_DISABLE_FORCE_OPEN_VK_ME, FEATURE_IM_GIF_AUTOPLAY, FEATURE_IM_MR_IN_VKAPP, FEATURE_MEMORIES_ENABLED, FEATURE_MENU_GAMES_CAROUSEL, FEATURE_MILKSHAKE, FEATURE_MILKSHAKE_CHANGE_FEED_BY_TIMEOUT, FEATURE_MILKSHAKE_NEWS_SCROLL_ON_BACK, FEATURE_MILKSHAKE_SWITCH_THEME_ON_TAP, FEATURE_ML_BRANDS, FEATURE_ML_FEATURES, FEATURE_ML_MODELS_LOADING, FEATURE_MONEY_TRANSFERS_VKPAY, FEATURE_MUSIC_ARTIST_CATALOG, FEATURE_MUSIC_NEW_CATALOG, FEATURE_NARRATIVE_SNIPPET_TYPE, FEATURE_NEWS_GAMES_IN_DISCOVER, FEATURE_NEWS_HEADER_SCROLL, FEATURE_NEW_FORMAT_SHOW_WPB, FEATURE_PODCASTS_PAGE, FEATURE_QR_CREATE_QR, FEATURE_QR_DYNAMIC_FRAME, FEATURE_QR_SCAN_FROM_PHOTO, FEATURE_QR_VISION_DECODER, FEATURE_QUEUE_COUNTERS, FEATURE_REEF, FEATURE_ROAMING_AUTOPLAY, FEATURE_SHARE_MSGS_ON_INVITE, FEATURE_STICKERS_BOT_LINK, FEATURE_STICKERS_NEW_CATALOG, FEATURE_STORIES_AVATAR, FEATURE_STORIES_FEED_TYPE, FEATURE_STORIES_SHOW_ALWAYS, FEATURE_STORY_ANSWER_PUBLIC, FEATURE_STORY_APP_STICKER, FEATURE_STORY_ARCHIVE, FEATURE_STORY_ARCHIVE_POST, FEATURE_STORY_BAKGROUND_ALL, FEATURE_STORY_BOX, FEATURE_STORY_CADRE, FEATURE_STORY_CAMERA_TOOLTIP, FEATURE_STORY_EDITOR_GALLERY, FEATURE_STORY_EDITOR_TYPE, FEATURE_STORY_ENDLESS_VIDEO, FEATURE_STORY_FAST_REACTIONS, FEATURE_STORY_GIF, FEATURE_STORY_GROUPED, FEATURE_STORY_HIGH_QUALITY, FEATURE_STORY_MASKS_FRONTAL, FEATURE_STORY_MENTION_ICON, FEATURE_STORY_MODERN_PUBLISH, FEATURE_STORY_MUSIC_EDITOR, FEATURE_STORY_MUSIC_REPLIES, FEATURE_STORY_MUSIC_REPLIES_2, FEATURE_STORY_NEW_FRAME, FEATURE_STORY_ONE_TIME, FEATURE_STORY_PHOTO_SHARING, FEATURE_STORY_PHOTO_STICKER, FEATURE_STORY_POLLS, FEATURE_STORY_POST_REPOST, FEATURE_STORY_PRELOADING, FEATURE_STORY_QUESTION, FEATURE_STORY_QUESTION_STYLE, FEATURE_STORY_RLOTTIE, FEATURE_STORY_RLOTTIE_CACHE, FEATURE_STORY_SAVE_DEFAULT_ON, FEATURE_STORY_SEND_DIALOG_LIST, FEATURE_STORY_STICKER_PACK, FEATURE_STORY_TIME, FEATURE_STORY_VIEWER_CAMERA, FEATURE_STORY_VOICE_ANSWER, FEATURE_STORY_WITH_CONTEXT, FEATURE_SUPERAPP_MENU, FEATURE_TRAFFIC_SAVER, FEATURE_VKPAY_WIDGET, FEATURE_VKUI_INTERNAL_TO_MINI_APPS, FEATURE_VKUI_TOKEN_CACHE, FEATURE_VK_APPS_SEARCH, FEATURE_VOTES_BALANCE, FEATURE_WEBVIEW_TOKEN_ACTIVE, FEATURE_MILKSHAKE_FORCE_DISABLED, FEATURE_MILKSHAKE_ACTIVATION_DISABLED, EXPERIMENT_NEWS_DISABLE_CACHE -> + case AB_IM_LONGPOLL_MSG_BATCHING, AB_IM_VIEW_POOL, AB_MULTI_GIFTS, AB_NEWS_VIDEO_LAYOUT_TEXT, AB_STICKERS_DISCOVER, AB_GIFTS_FROM_KEYBOARD, FEATURE_FEED_DEFAULT_LIST_ALWAYS, EXPERIMENT_NEWS_VIDEO_LAYOUT_TEXT, FEATURE_DISCOVER_CATEGORIES, FEATURE_FAVE_PERF_IMPROVE, FEATURE_GROUP_ADMIN_MESSAGES, FEATURE_GROUP_MSG_PUSH_PARAM, FEATURE_IMAGE_QUALITY_UPGRADE, FEATURE_IM_AUDIO_MSG_TRANSCRIPT, FEATURE_IM_CASPER_MSGS, FEATURE_IM_DISABLE_FORCE_OPEN_VK_ME, FEATURE_IM_GIF_AUTOPLAY, FEATURE_IM_MR_IN_VKAPP, FEATURE_MEMORIES_ENABLED, FEATURE_MENU_GAMES_CAROUSEL, FEATURE_MILKSHAKE, FEATURE_MILKSHAKE_CHANGE_FEED_BY_TIMEOUT, FEATURE_MILKSHAKE_NEWS_SCROLL_ON_BACK, FEATURE_MILKSHAKE_SWITCH_THEME_ON_TAP, FEATURE_ML_BRANDS, FEATURE_ML_FEATURES, FEATURE_ML_MODELS_LOADING, FEATURE_MONEY_TRANSFERS_VKPAY, FEATURE_MUSIC_ARTIST_CATALOG, FEATURE_MUSIC_NEW_CATALOG, FEATURE_NARRATIVE_SNIPPET_TYPE, FEATURE_NEWS_GAMES_IN_DISCOVER, FEATURE_NEWS_HEADER_SCROLL, FEATURE_NEW_FORMAT_SHOW_WPB, FEATURE_PODCASTS_PAGE, FEATURE_QR_CREATE_QR, FEATURE_QR_DYNAMIC_FRAME, FEATURE_QR_SCAN_FROM_PHOTO, FEATURE_QR_VISION_DECODER, FEATURE_QUEUE_COUNTERS, FEATURE_REEF, FEATURE_ROAMING_AUTOPLAY, FEATURE_SHARE_MSGS_ON_INVITE, FEATURE_STICKERS_BOT_LINK, FEATURE_STICKERS_NEW_CATALOG, FEATURE_STORIES_AVATAR, FEATURE_STORIES_FEED_TYPE, FEATURE_STORIES_SHOW_ALWAYS, FEATURE_STORY_ANSWER_PUBLIC, FEATURE_STORY_APP_STICKER, FEATURE_STORY_ARCHIVE, FEATURE_STORY_ARCHIVE_POST, FEATURE_STORY_BAKGROUND_ALL, FEATURE_STORY_BOX, FEATURE_STORY_CADRE, FEATURE_STORY_CAMERA_TOOLTIP, FEATURE_STORY_EDITOR_GALLERY, FEATURE_STORY_EDITOR_TYPE, FEATURE_STORY_ENDLESS_VIDEO, FEATURE_STORY_FAST_REACTIONS, FEATURE_STORY_GIF, FEATURE_STORY_GROUPED, FEATURE_STORY_HIGH_QUALITY, FEATURE_STORY_MASKS_FRONTAL, FEATURE_STORY_MENTION_ICON, FEATURE_STORY_MODERN_PUBLISH, FEATURE_STORY_MUSIC_EDITOR, FEATURE_STORY_MUSIC_REPLIES, FEATURE_STORY_MUSIC_REPLIES_2, FEATURE_STORY_NEW_FRAME, FEATURE_STORY_ONE_TIME, FEATURE_STORY_PHOTO_SHARING, FEATURE_STORY_PHOTO_STICKER, FEATURE_STORY_POLLS, FEATURE_STORY_POST_REPOST, FEATURE_STORY_PRELOADING, FEATURE_STORY_QUESTION, FEATURE_STORY_QUESTION_STYLE, FEATURE_STORY_RLOTTIE, FEATURE_STORY_RLOTTIE_CACHE, FEATURE_STORY_SAVE_DEFAULT_ON, FEATURE_STORY_SEND_DIALOG_LIST, FEATURE_STORY_STICKER_PACK, FEATURE_STORY_TIME, FEATURE_STORY_VIEWER_CAMERA, FEATURE_STORY_VOICE_ANSWER, FEATURE_STORY_WITH_CONTEXT, FEATURE_SUPERAPP_MENU, FEATURE_TRAFFIC_SAVER, FEATURE_VKPAY_WIDGET, FEATURE_VKUI_INTERNAL_TO_MINI_APPS, FEATURE_VKUI_TOKEN_CACHE, FEATURE_VK_APPS_SEARCH, FEATURE_VOTES_BALANCE, FEATURE_WEBVIEW_TOKEN_ACTIVE, FEATURE_MILKSHAKE_FORCE_DISABLED, FEATURE_MILKSHAKE_ACTIVATION_DISABLED, EXPERIMENT_NEWS_DISABLE_CACHE -> true; default -> false; }; @@ -22,7 +23,7 @@ public class TogglesHook { case FEATURE_MILKSHAKE_FORCE_DISABLED, FEATURE_MILKSHAKE_ACTIVATION_DISABLED -> !milkshake(); case AB_NEWS_VIDEO_LAYOUT_TEXT, FEATURE_COMPACT_REPOST, EXPERIMENT_NEWS_VIDEO_LAYOUT_TEXT -> postsredesign(); - case FEATURE_IMAGE_QUALITY_UPGRADE -> !getBoolValue("compressPhotos", true); + case FEATURE_IMAGE_QUALITY_UPGRADE -> MediaImageEncoder.needToSkipCompression(); case FEATURE_MENU_GAMES_CAROUSEL -> miniapps(); default -> true; }; diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java index bd5d81caa..379c7f94d 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java @@ -12,6 +12,7 @@ import com.aefyr.tsg.g2.TelegramStickersService; import com.vk.about.AboutAppFragment; import com.vk.balance.BalanceFragment; import com.vk.identity.fragments.IdentityListFragment; +import com.vk.medianative.MediaImageEncoder; import com.vk.notifications.settings.NotificationsSettingsFragment; import com.vk.webapp.fragments.PrivacyFragment; import com.vtosters.lite.MainActivity; @@ -399,7 +400,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment impleme getPreferenceScreen(), "", requireContext().getString(R.string.vtlmedia), - getValAsString(R.string.sett_compress_photos, Preferences.getBoolValue("compressPhotos", true)), + getValAsString(R.string.sett_compress_photos, MediaImageEncoder.needToCompress()), R.drawable.ic_media_outline_28, preference -> { NavigatorUtils.switchFragment(requireContext(), MediaFragment.class); diff --git a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java index 66d7d0608..954d3e9a0 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Build; import android.os.StrictMode; +import com.vk.medianative.MediaImageEncoder; import com.vtosters.lite.data.Users; import com.vtosters.lite.fragments.SettingsListFragment; import ru.vtosters.lite.BuildConfig; @@ -334,9 +335,7 @@ public class Preferences { } public static int compress(int origquality) { - if (!getBoolValue("compressPhotos", true)) { - return 100; - } + if (MediaImageEncoder.needToSkipCompression()) return 100; return origquality; } } diff --git a/smali/res/menu/photo_viewer.xml b/smali/res/menu/photo_viewer.xml index aaa3c723c..3a28523da 100644 --- a/smali/res/menu/photo_viewer.xml +++ b/smali/res/menu/photo_viewer.xml @@ -40,6 +40,10 @@ android:id="@id/report" android:showAsAction="never" android:title="@string/report_content" /> + Выбрать вручную Предустановленные цвета + + Сжатие без потерь + Стандартное сжатие + Эффективное сжатие + diff --git a/smali/res/values/arrays.xml b/smali/res/values/arrays.xml index 0f12fd056..f42e06642 100644 --- a/smali/res/values/arrays.xml +++ b/smali/res/values/arrays.xml @@ -891,4 +891,14 @@ Color Picker From Palettes + + Lossless compression + Default compression + Effective compression + + + skip + jpeg + native + diff --git a/smali/res/values/ids.xml b/smali/res/values/ids.xml index 5157840f5..aa58a3f6d 100644 --- a/smali/res/values/ids.xml +++ b/smali/res/values/ids.xml @@ -3920,4 +3920,5 @@ + diff --git a/smali/res/xml/preferences_media.xml b/smali/res/xml/preferences_media.xml index 7bb77484b..e0e552f07 100644 --- a/smali/res/xml/preferences_media.xml +++ b/smali/res/xml/preferences_media.xml @@ -1,16 +1,18 @@ - + ()V - .locals 0 - - .line 1 - invoke-direct {p0}, Ljava/lang/Object;->()V - - return-void -.end method - -.method private static a(Ljava/io/FileOutputStream;Ljava/lang/String;)V - .locals 2 - - .line 8 - :try_start_0 - new-instance v0, Ljava/lang/StringBuilder; - - invoke-direct {v0}, Ljava/lang/StringBuilder;->()V - - const-string v1, "jpeg " - - invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; - - invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; - - const-string p1, " size=" - - invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; - - invoke-virtual {p0}, Ljava/io/FileOutputStream;->getChannel()Ljava/nio/channels/FileChannel; - - move-result-object p0 - - invoke-virtual {p0}, Ljava/nio/channels/FileChannel;->position()J - - move-result-wide p0 - - invoke-virtual {v0, p0, p1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder; - - invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; - :try_end_0 - .catchall {:try_start_0 .. :try_end_0} :catchall_0 - - :catchall_0 - return-void -.end method - -.method private static a(Ljava/io/OutputStream;)V - .locals 0 - - if-eqz p0, :cond_0 - - .line 9 - :try_start_0 - invoke-virtual {p0}, Ljava/io/OutputStream;->close()V - :try_end_0 - .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0 - - :catch_0 - :cond_0 - return-void -.end method - -.method private static a(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - .locals 2 - - const/4 v0, 0x0 - - .line 1 - :try_start_0 - new-instance v1, Ljava/io/FileOutputStream; - - invoke-direct {v1, p1}, Ljava/io/FileOutputStream;->(Ljava/io/File;)V - :try_end_0 - .catchall {:try_start_0 .. :try_end_0} :catchall_1 - - .line 2 - :try_start_1 - sget-object p1, Landroid/graphics/Bitmap$CompressFormat;->JPEG:Landroid/graphics/Bitmap$CompressFormat; - - invoke-static {p2}, Lru/vtosters/lite/utils/Preferences;->compress(I)I - - move-result p2 - - invoke-virtual {p0, p1, p2, v1}, Landroid/graphics/Bitmap;->compress(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z - - move-result p0 - - const-string p1, "system" - - .line 3 - invoke-static {v1, p1}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/FileOutputStream;Ljava/lang/String;)V - :try_end_1 - .catchall {:try_start_1 .. :try_end_1} :catchall_0 - - .line 4 - invoke-static {v1}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - return p0 - - :catchall_0 - move-exception p0 - - goto :goto_0 - - :catchall_1 - move-exception p0 - - move-object v1, v0 - - .line 5 - :goto_0 - :try_start_2 - const-class p1, Lcom/vk/medianative/MediaImageEncoder; - - invoke-virtual {p1}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String; - - move-result-object p1 - - new-instance p2, Ljava/lang/StringBuilder; - - invoke-direct {p2}, Ljava/lang/StringBuilder;->()V - - const-string v0, "jpeg system compressing error! " - - invoke-virtual {p2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; - - invoke-virtual {p2, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder; - - invoke-virtual {p2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; - - move-result-object p0 - - invoke-static {p1, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I - :try_end_2 - .catchall {:try_start_2 .. :try_end_2} :catchall_2 - - .line 6 - invoke-static {v1}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - const/4 p0, 0x0 - - return p0 - - :catchall_2 - move-exception p0 - - invoke-static {v1}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - .line 7 - throw p0 -.end method - -.method private static b(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - .locals 6 - - .line 1 - const-class v0, Lcom/vk/medianative/MediaImageEncoder; - - const/4 v1, 0x0 - - const/4 v2, 0x0 - - .line 2 - :try_start_0 - invoke-static {}, Lcom/vk/medianative/MediaNative;->isX86()Z - - move-result v3 - - const/4 v4, 0x1 - - if-nez v3, :cond_1 - - invoke-static {}, Lcom/vk/medianative/MediaNative;->isAsus()Z - - move-result v3 - - if-nez v3, :cond_1 - - sget v3, Landroid/os/Build$VERSION;->SDK_INT:I - - const/16 v5, 0x18 - - if-ge v3, v5, :cond_0 - - goto :goto_0 - - :cond_0 - const/4 v3, 0x0 - - goto :goto_1 - - :cond_1 - :goto_0 - const/4 v3, 0x1 - - :goto_1 - if-eqz v3, :cond_2 - - .line 3 - invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String; - - move-result-object p0 - - const-string p1, "jpeg turbo on not supported device!" - - invoke-static {p0, p1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I - :try_end_0 - .catchall {:try_start_0 .. :try_end_0} :catchall_1 - - .line 4 - invoke-static {v2}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - return v1 - - .line 5 - :cond_2 - :try_start_1 - new-instance v3, Ljava/io/FileOutputStream; - - invoke-direct {v3, p1}, Ljava/io/FileOutputStream;->(Ljava/io/File;)V - :try_end_1 - .catchall {:try_start_1 .. :try_end_1} :catchall_1 - - .line 6 - :try_start_2 - invoke-virtual {p0}, Landroid/graphics/Bitmap;->isRecycled()Z - - move-result p1 - - if-nez p1, :cond_5 - - invoke-virtual {p0}, Landroid/graphics/Bitmap;->getHeight()I - - move-result p1 - - invoke-virtual {p0}, Landroid/graphics/Bitmap;->getWidth()I - - move-result v2 - - mul-int p1, p1, v2 - - if-nez p1, :cond_3 - - goto :goto_2 - - .line 7 - :cond_3 - invoke-static {p2}, Lru/vtosters/lite/utils/Preferences;->compress(I)I - - move-result p2 - - invoke-static {p0, p2}, Lcom/vk/medianative/MediaNative;->compressBitmapJpeg(Landroid/graphics/Bitmap;I)[B - - move-result-object p0 - - if-eqz p0, :cond_4 - - .line 8 - invoke-virtual {v3, p0}, Ljava/io/FileOutputStream;->write([B)V - - const-string p0, "turbo" - - .line 9 - invoke-static {v3, p0}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/FileOutputStream;Ljava/lang/String;)V - :try_end_2 - .catchall {:try_start_2 .. :try_end_2} :catchall_0 - - .line 10 - invoke-static {v3}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - return v4 - - :cond_4 - invoke-static {v3}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - goto :goto_4 - - :cond_5 - :goto_2 - invoke-static {v3}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - return v1 - - :catchall_0 - move-exception p0 - - move-object v2, v3 - - goto :goto_3 - - :catchall_1 - move-exception p0 - - .line 11 - :goto_3 - :try_start_3 - invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String; - - move-result-object p1 - - new-instance p2, Ljava/lang/StringBuilder; - - invoke-direct {p2}, Ljava/lang/StringBuilder;->()V - - const-string v0, "jpeg turbo compressing error! " - - invoke-virtual {p2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; - - invoke-virtual {p2, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder; - - invoke-virtual {p2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; - - move-result-object p0 - - invoke-static {p1, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I - :try_end_3 - .catchall {:try_start_3 .. :try_end_3} :catchall_2 - - .line 12 - invoke-static {v2}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - :goto_4 - return v1 - - :catchall_2 - move-exception p0 - - invoke-static {v2}, Lcom/vk/medianative/MediaImageEncoder;->a(Ljava/io/OutputStream;)V - - .line 13 - throw p0 -.end method - -.method public static encodeJpeg(Landroid/graphics/Bitmap;Ljava/io/File;)Z - .locals 1 - - .line 1 - sget v0, Lcom/vk/medianative/MediaImageEncoder;->b:I - - invoke-static {p0, p1, v0}, Lcom/vk/medianative/MediaImageEncoder;->encodeJpeg(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - - move-result p0 - - return p0 -.end method - -.method public static encodeJpeg(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - .locals 2 - - if-eqz p0, :cond_2 - - .line 2 - invoke-virtual {p0}, Landroid/graphics/Bitmap;->isRecycled()Z - - move-result v0 - - if-nez v0, :cond_2 - - invoke-virtual {p0}, Landroid/graphics/Bitmap;->getWidth()I - - move-result v0 - - invoke-virtual {p0}, Landroid/graphics/Bitmap;->getHeight()I - - move-result v1 - - mul-int v0, v0, v1 - - if-nez v0, :cond_0 - - goto :goto_0 - - .line 3 - :cond_0 - sget-object v0, Lcom/vk/toggle/Features$Type;->FEATURE_MOZJPEG:Lcom/vk/toggle/Features$Type; - - invoke-static {v0}, Lcom/vk/toggle/FeatureManager;->b(Lcom/vk/toggle/Features$Type;)Z - - move-result v0 - - if-eqz v0, :cond_1 - - .line 4 - invoke-static {p0, p1, p2}, Lcom/vk/medianative/MediaImageEncoder;->b(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - - move-result v0 - - if-eqz v0, :cond_1 - - const/4 p0, 0x1 - - return p0 - - .line 5 - :cond_1 - invoke-static {p0, p1, p2}, Lcom/vk/medianative/MediaImageEncoder;->a(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - - move-result p0 - - return p0 - - :cond_2 - :goto_0 - const/4 p0, 0x0 - - return p0 -.end method - -.method public static encodeJpegWithoutCompression(Landroid/graphics/Bitmap;Ljava/io/File;)Z - .locals 1 - - .line 1 - sget v0, Lcom/vk/medianative/MediaImageEncoder;->a:I - - invoke-static {p0, p1, v0}, Lcom/vk/medianative/MediaImageEncoder;->encodeJpeg(Landroid/graphics/Bitmap;Ljava/io/File;I)Z - - move-result p0 - - return p0 -.end method diff --git a/smali/smali_classes5/com/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6$1.smali b/smali/smali_classes5/com/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6$1.smali index 207e35536..53f96e6f5 100644 --- a/smali/smali_classes5/com/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6$1.smali +++ b/smali/smali_classes5/com/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6$1.smali @@ -63,24 +63,7 @@ .method public final invoke()Z .locals 3 - .line 2 - iget-object v0, p0, Lcom/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6$1;->this$0:Lcom/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6; - - iget-object v1, v0, Lcom/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6;->$sp:Lkotlin/Lazy2; - - iget-object v0, v0, Lcom/vtosters/lite/im/ImEngineProvider$createVkAppConfig$6;->$sp$metadata:Lkotlin/u/KProperty5; - - invoke-interface {v1}, Lkotlin/Lazy2;->getValue()Ljava/lang/Object; - - move-result-object v0 - - check-cast v0, Landroid/content/SharedPreferences; - - const-string v1, "compressPhotos" - - const/4 v2, 0x0 - - invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences;->getBoolean(Ljava/lang/String;Z)Z + invoke-static {}, Lcom/vk/medianative/MediaImageEncoder;->needToCompress()Z move-result v0 diff --git a/smali/smali_classes5/com/vtosters/lite/im/converters/ImPhotoConverter$a.smali b/smali/smali_classes5/com/vtosters/lite/im/converters/ImPhotoConverter$a.smali index 08518b75f..d9f7efff1 100644 --- a/smali/smali_classes5/com/vtosters/lite/im/converters/ImPhotoConverter$a.smali +++ b/smali/smali_classes5/com/vtosters/lite/im/converters/ImPhotoConverter$a.smali @@ -45,7 +45,7 @@ if-eqz v0, :cond_0 - const/16 v0, 0x1000 + const/16 v0, 0x800 goto :goto_0 @@ -79,7 +79,7 @@ if-eqz v0, :cond_0 - const/16 v0, 0x1000 + const/16 v0, 0xa00 goto :goto_0 diff --git a/smali/smali_classes5/com/vtosters/lite/upload/UploadCompressStrategy$a2.smali b/smali/smali_classes5/com/vtosters/lite/upload/UploadCompressStrategy$a2.smali index b3dc37bcd..9fdb1d0ba 100644 --- a/smali/smali_classes5/com/vtosters/lite/upload/UploadCompressStrategy$a2.smali +++ b/smali/smali_classes5/com/vtosters/lite/upload/UploadCompressStrategy$a2.smali @@ -45,7 +45,7 @@ if-eqz v0, :cond_0 - const/16 v0, 0x1000 + const/16 v0, 0x800 goto :goto_0 @@ -79,7 +79,7 @@ if-eqz v0, :cond_0 - const/16 v0, 0x1000 + const/16 v0, 0xa00 goto :goto_0 diff --git a/smali/smali_classes5/com/vtosters/lite/upload/l/PhotoUploadTask.smali b/smali/smali_classes5/com/vtosters/lite/upload/l/PhotoUploadTask.smali index 746512943..02f5eae42 100644 --- a/smali/smali_classes5/com/vtosters/lite/upload/l/PhotoUploadTask.smali +++ b/smali/smali_classes5/com/vtosters/lite/upload/l/PhotoUploadTask.smali @@ -119,16 +119,7 @@ .method protected w()Ljava/lang/String; .locals 3 - .line 1 - invoke-static {}, Lcom/vk/core/preference/Preference;->a()Landroid/content/SharedPreferences; - - move-result-object v0 - - const-string v1, "compressPhotos" - - const/4 v2, 0x1 - - invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences;->getBoolean(Ljava/lang/String;Z)Z + invoke-static {}, Lcom/vk/medianative/MediaImageEncoder;->needToCompress()Z move-result v0