Skip to content

Commit

Permalink
Patch 2.11.1 SDK 2.11.1 UI
Browse files Browse the repository at this point in the history
Release 2.11.1
  • Loading branch information
prateek-kommunicate authored Nov 15, 2024
2 parents 4e123ad + 482840f commit fb13996
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
alias libs.plugins.android.application apply false
alias libs.plugins.google.services apply false
alias libs.plugins.kotlin.android apply false
alias libs.plugins.jfrog apply false
alias libs.plugins.jfrog apply true
alias libs.plugins.android.library apply false
alias libs.plugins.google.secrets apply false
alias libs.plugins.sentry apply false
Expand Down
8 changes: 5 additions & 3 deletions kommunicate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ plugins {
alias libs.plugins.android.library
alias libs.plugins.kotlin.android
alias libs.plugins.google.secrets
id "maven-publish"
alias libs.plugins.jfrog
alias libs.plugins.meaven.local
}

android {
Expand All @@ -17,7 +18,7 @@ android {
compileSdk 34
targetSdkVersion 34
versionCode 1
versionName "2.11.0"
versionName "2.11.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "KOMMUNICATE_VERSION", "\"" + versionName + "\""
buildConfigField "String", "CHAT_SERVER_URL", '"https://chat.kommunicate.io"'
Expand Down Expand Up @@ -140,7 +141,8 @@ publishing {
}
}
}
/*artifactoryPublish {
/*
artifactoryPublish {
publications(publishing.publications.aar)
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ public static String getExtension(String uri) {
}
}

public static boolean deleteFile(Uri uri) {
if (uri == null) {
Log.w(TAG, "Cannot delete file: Uri is null");
return false;
}
if (uri.getPath() == null) {
Log.w(TAG, "Cannot delete file: Uri path is null");
return false;
}
File file = new File(uri.getPath());
try {
boolean deleted = file.delete();
if (!deleted) {
Log.w(TAG, "Failed to delete file: " + uri.getPath());
}
return deleted;
} catch (SecurityException e) {
Log.e(TAG, "Security exception while deleting file: " + uri.getPath(), e);
return false;
}
}

/**
* @return Whether the URI is a local one.
*/
Expand Down Expand Up @@ -1021,27 +1043,44 @@ public static boolean isContentScheme(Uri uri) {
}

public static Uri compressImage(Uri uri, Context context, String fileName) {
Bitmap originalBitmap = null;
ByteArrayOutputStream outputStream = null;
FileOutputStream fileOutputStream = null;
try {
// Load and compress the bitmap
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap originalBitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, options);
originalBitmap = BitmapFactory.decodeStream(
context.getContentResolver().openInputStream(uri), null, options);

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
originalBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outputStream);

File tempFile = File.createTempFile(fileName, null, context.getCacheDir());
tempFile.deleteOnExit();

FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
// Write the compressed bitmap to a cache file
File cacheFile = new File(context.getCacheDir(), fileName);
fileOutputStream = new FileOutputStream(cacheFile);
fileOutputStream.write(outputStream.toByteArray());
fileOutputStream.flush();
fileOutputStream.close();

return Uri.fromFile(tempFile);
// Return the URI
return Uri.fromFile(cacheFile);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (originalBitmap != null && !originalBitmap.isRecycled()) {
originalBitmap.recycle();
}
try {
if (outputStream != null) {
outputStream.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e) {
Log.e(TAG, "Error closing output stream", e);
}
}
return null;
}

public static Uri compressVideo(Context context, Uri uri, File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,30 @@ public AssetFileDescriptor openDocumentThumbnail(final String documentId, final
}
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(documentId, options);
// Write out the thumbnail to a temporary file
File tempFile = null;
FileOutputStream out = null;

ParcelFileDescriptor[] pipe;
try {
tempFile = File.createTempFile("thumbnail", null, getContext().getCacheDir());
out = new FileOutputStream(tempFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
pipe = ParcelFileDescriptor.createPipe();
} catch (IOException e) {
Log.e(LocalStorageProvider.class.getSimpleName(), "Error writing thumbnail", e);
Log.e(LocalStorageProvider.class.getSimpleName(), "Error creating pipe", e);
return null;
} finally {
if (out != null)
try {
out.close();
} catch (IOException e) {
Log.e(LocalStorageProvider.class.getSimpleName(), "Error closing thumbnail", e);
}
}

// Write the bitmap data to the output stream in a separate thread
new Thread(() -> {
try (ParcelFileDescriptor.AutoCloseOutputStream out =
new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])) {
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (IOException e) {
Log.e(LocalStorageProvider.class.getSimpleName(), "Error writing thumbnail to pipe", e);
}
}).start();

// It appears the Storage Framework UI caches these results quite
// aggressively so there is little reason to
// write your own caching layer beyond what you need to return a single
// AssetFileDescriptor
return new AssetFileDescriptor(ParcelFileDescriptor.open(tempFile,
ParcelFileDescriptor.MODE_READ_ONLY), 0,
return new AssetFileDescriptor(pipe[0], 0,
AssetFileDescriptor.UNKNOWN_LENGTH);
}

Expand Down
12 changes: 7 additions & 5 deletions kommunicateui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias libs.plugins.android.library
alias libs.plugins.kotlin.android
alias libs.plugins.jfrog
alias libs.plugins.meaven.local
}

Expand All @@ -15,7 +16,7 @@ android {
targetSdkVersion 34
minSdkVersion 21
versionCode 1
versionName "2.11.0"
versionName "2.11.1"
buildToolsVersion = '34.0.0'
consumerProguardFiles 'proguard-rules.txt'
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -129,8 +130,9 @@ publishing {
}
}
}
//artifactoryPublish {
// publications(publishing.publications.aar)
//}
//

/*
artifactoryPublish {
publications(publishing.publications.aar)
}
*/
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package com.applozic.mobicomkit.uiwidgets.async;

import static android.os.Environment.getExternalStoragePublicDirectory;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

import com.applozic.mobicomkit.api.attachment.FileClientService;
import com.applozic.mobicomkit.uiwidgets.kommunicate.callbacks.PrePostUIMethods;
import com.applozic.mobicommons.file.FileUtils;
import com.iceteck.silicompressorr.SiliCompressor;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Locale;

/**
* a async task that will write the given file with the given "uri" to the "file"
Expand Down Expand Up @@ -66,6 +53,7 @@ protected Boolean doInBackground(Void... voids) {
}
if (fileClientService != null) {
fileClientService.writeFile(uri, file);
FileUtils.deleteFile(uri);
}
return true;
}
Expand Down

0 comments on commit fb13996

Please sign in to comment.