diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 4c853526..d418d468 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -62,6 +62,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_WHITE; import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; +import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; /** * Custom {@link android.support.v7.widget.RecyclerView.Adapter} used for topics. @@ -194,7 +195,7 @@ class TopicAdapter extends RecyclerView.Adapter { attached.setClickable(true); attached.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); - attached.setText(faIconFromFilename(attachedFile.getFilename()) + " " + attached.setText(faIconFromFilename(context, attachedFile.getFilename()) + " " + attachedFile.getFilename() + attachedFile.getFileInfo()); attached.setTextColor(filesTextColor); attached.setPadding(0, 3, 0, 3); @@ -733,37 +734,4 @@ class TopicAdapter extends RecyclerView.Adapter { public interface OnPostFocusChangeListener { void onPostFocusChange(int position); } - - /** - * Returns a String with a single FontAwesome typeface character corresponding to this file's - * extension. - * - * @param filename String with filename containing file's extension - * @return FontAwesome character according to file's type - * @see FontAwesome - */ - @NonNull - private String faIconFromFilename(String filename) { - filename = filename.toLowerCase(); - - if (filename.contains("jpg") || filename.contains("gif") || filename.contains("jpeg") - || filename.contains("png")) - return context.getResources().getString(R.string.fa_file_image_o); - else if (filename.contains("pdf")) - return context.getResources().getString(R.string.fa_file_pdf_o); - else if (filename.contains("zip") || filename.contains("rar") || filename.contains("tar.gz")) - return context.getResources().getString(R.string.fa_file_zip_o); - else if (filename.contains("txt")) - return context.getResources().getString(R.string.fa_file_text_o); - else if (filename.contains("doc") || filename.contains("docx")) - return context.getResources().getString(R.string.fa_file_word_o); - else if (filename.contains("xls") || filename.contains("xlsx")) - return context.getResources().getString(R.string.fa_file_excel_o); - else if (filename.contains("pps")) - return context.getResources().getString(R.string.fa_file_powerpoint_o); - else if (filename.contains("mpg")) - return context.getResources().getString(R.string.fa_file_video_o); - - return context.getResources().getString(R.string.fa_file); - } } \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index 20fa5d2c..6477ea1f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; @@ -73,6 +74,7 @@ import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.BUND import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_DESCRIPTION; import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_FILENAME; import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE; +import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; public class UploadActivity extends BaseActivity { /** @@ -391,8 +393,9 @@ public class UploadActivity extends BaseActivity { } String uploadID = UUID.randomUUID().toString(); - if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID), categorySelected, - uploadTitleText, uploadDescriptionText[0], fileIcon, uploaderProfileIndex, + if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID, + editTextFilename), categorySelected, uploadTitleText, + uploadDescriptionText[0], fileIcon, uploaderProfileIndex, tempFileUri == null ? filesList.get(0).getFileUri() : tempFileUri)) { @@ -449,12 +452,8 @@ public class UploadActivity extends BaseActivity { @Override protected void onDestroy() { super.onDestroy(); - if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING) + if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING) { parseUploadPageTask.cancel(true); - - //Deletes any photo file previously created, as it is not going to be used - if (photoFileCreated != null) { - storage.deleteFile(photoFileCreated.getAbsolutePath()); } } @@ -644,9 +643,9 @@ public class UploadActivity extends BaseActivity { inflate(R.layout.activity_upload_file_list_row, null); TextView itemText = newFileRow.findViewById(R.id.upload_file_item_text); - Drawable filenameDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_attach_file_white_24dp); - itemText.setCompoundDrawablesRelativeWithIntrinsicBounds(filenameDrawable, null, null, null); - itemText.setText(filename); + itemText.setTypeface(Typeface.createFromAsset(this.getAssets() + , "fonts/fontawesome-webfont.ttf")); + itemText.setText(faIconFromFilename(this, filename) + " " + filename); newFileRow.findViewById(R.id.upload_file_item_remove). setOnClickListener(view -> { @@ -669,9 +668,10 @@ public class UploadActivity extends BaseActivity { filesListView.setVisibility(View.VISIBLE); } - private static UploadNotificationConfig getConfigForUpload(Context context, String uploadID) { + private static UploadNotificationConfig getConfigForUpload(Context context, String uploadID, String filename) { UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); + uploadNotificationConfig.setTitleForAllStatuses("Uploading " + filename); uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; @@ -680,7 +680,6 @@ public class UploadActivity extends BaseActivity { uploadNotificationConfig.getCancelled().iconColorResourceID = android.R.drawable.stat_sys_upload_done; Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD); - //combinedActionsIntent.setAction(UploadsReceiver.ACTION_COMBINED_UPLOAD); combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context, @@ -1009,7 +1008,7 @@ public class UploadActivity extends BaseActivity { String uploadID = UUID.randomUUID().toString(); if (!uploadFile(weakActivity.get(), uploadID, - getConfigForUpload(weakActivity.get(), uploadID), categorySelected, + getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected, uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex, zipFileUri)) { Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java b/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java index 9897ae81..2eaa3856 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java @@ -43,8 +43,8 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { switch (intentAction) { case ACTION_CANCEL_UPLOAD: - String notificationID = intentBundle.getString(UPLOAD_ID_KEY); - UploadService.stopUpload(notificationID); + String uploadID = intentBundle.getString(UPLOAD_ID_KEY); + UploadService.stopUpload(uploadID); break; case ACTION_RETRY_UPLOAD: //TODO diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java index b005ac4f..324017fb 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java @@ -10,6 +10,8 @@ import android.webkit.MimeTypeMap; import java.io.File; +import gr.thmmy.mthmmy.R; + import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; public class FileUtils { @@ -82,4 +84,37 @@ public class FileUtils { } return -1; } + + /** + * Returns a String with a single FontAwesome typeface character corresponding to this file's + * extension. + * + * @param filename String with filename containing file's extension + * @return FontAwesome character according to file's type + * @see FontAwesome + */ + @NonNull + public static String faIconFromFilename(Context context, String filename) { + filename = filename.toLowerCase(); + + if (filename.contains("jpg") || filename.contains("gif") || filename.contains("jpeg") + || filename.contains("png")) + return context.getResources().getString(R.string.fa_file_image_o); + else if (filename.contains("pdf")) + return context.getResources().getString(R.string.fa_file_pdf_o); + else if (filename.contains("zip") || filename.contains("rar") || filename.contains("tar.gz")) + return context.getResources().getString(R.string.fa_file_zip_o); + else if (filename.contains("txt")) + return context.getResources().getString(R.string.fa_file_text_o); + else if (filename.contains("doc") || filename.contains("docx")) + return context.getResources().getString(R.string.fa_file_word_o); + else if (filename.contains("xls") || filename.contains("xlsx")) + return context.getResources().getString(R.string.fa_file_excel_o); + else if (filename.contains("pps")) + return context.getResources().getString(R.string.fa_file_powerpoint_o); + else if (filename.contains("mpg")) + return context.getResources().getString(R.string.fa_file_video_o); + + return context.getResources().getString(R.string.fa_file); + } } diff --git a/app/src/main/res/drawable/ic_attach_file_white_24dp.xml b/app/src/main/res/drawable/ic_attach_file_white_24dp.xml deleted file mode 100644 index 4834305b..00000000 --- a/app/src/main/res/drawable/ic_attach_file_white_24dp.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/activity_upload_file_list_row.xml b/app/src/main/res/layout/activity_upload_file_list_row.xml index ab2c7408..a2567ddc 100644 --- a/app/src/main/res/layout/activity_upload_file_list_row.xml +++ b/app/src/main/res/layout/activity_upload_file_list_row.xml @@ -11,7 +11,6 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" - android:drawablePadding="5dp" android:ellipsize="marquee" android:singleLine="true" android:textColor="@color/primary_text" />