From bf127f6fe97c94d254bde2542730187e58d5294d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 4 Jul 2021 22:57:30 +0800 Subject: Remove file extension from uploaded image's file name after uploading an image. Send Toast and Snackbar messages when uploading an image. --- .../infinityforreddit/activities/CommentActivity.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 93e4e2a8..2c3e10b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -433,6 +433,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA } private void uploadImageToReddit(Uri imageUri) { + Toast.makeText(this, R.string.uploading_image, Toast.LENGTH_SHORT).show(); Handler handler = new Handler(); mExecutor.execute(() -> { try { @@ -449,8 +450,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA int start = Math.max(commentEditText.getSelectionStart(), 0); int end = Math.max(commentEditText.getSelectionEnd(), 0); commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), - "[" + imageUrlOrError + "](" + imageUrlOrError + ")", - 0, "[]()".length() + imageUrlOrError.length() + imageUrlOrError.length()); + "[" + fileName + "](" + imageUrlOrError + ")", + 0, "[]()".length() + fileName.length() + imageUrlOrError.length()); + Snackbar.make(coordinatorLayout, R.string.upload_image_success, Snackbar.LENGTH_LONG).show(); } else { Toast.makeText(CommentActivity.this, R.string.upload_image_failed, Toast.LENGTH_LONG).show(); } @@ -497,7 +499,11 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA if (cursor != null) { int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); cursor.moveToFirst(); - return cursor.getString(nameIndex); + String fileName = cursor.getString(nameIndex); + if(fileName != null && fileName.contains(".")) { + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + } + return fileName; } } -- cgit v1.2.3