Browse Source

Upload file icon corresponds to file type, Notification title change

uploads
Apostolos Fanakis 6 years ago
parent
commit
c2f9c524d3
  1. 36
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  2. 25
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java
  4. 35
      app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java
  5. 4
      app/src/main/res/drawable/ic_attach_file_white_24dp.xml
  6. 1
      app/src/main/res/layout/activity_upload_file_list_row.xml

36
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_WHITE;
import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW;
import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; 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. * Custom {@link android.support.v7.widget.RecyclerView.Adapter} used for topics.
@ -194,7 +195,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
attached.setClickable(true); attached.setClickable(true);
attached.setTypeface(Typeface.createFromAsset(context.getAssets() attached.setTypeface(Typeface.createFromAsset(context.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
attached.setText(faIconFromFilename(attachedFile.getFilename()) + " " attached.setText(faIconFromFilename(context, attachedFile.getFilename()) + " "
+ attachedFile.getFilename() + attachedFile.getFileInfo()); + attachedFile.getFilename() + attachedFile.getFileInfo());
attached.setTextColor(filesTextColor); attached.setTextColor(filesTextColor);
attached.setPadding(0, 3, 0, 3); attached.setPadding(0, 3, 0, 3);
@ -733,37 +734,4 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public interface OnPostFocusChangeListener { public interface OnPostFocusChangeListener {
void onPostFocusChange(int position); void onPostFocusChange(int position);
} }
/**
* Returns a String with a single FontAwesome typeface character corresponding to this file's
* extension.
*
* @param filename String with filename <b>containing file's extension</b>
* @return FontAwesome character according to file's type
* @see <a href="http://fontawesome.io/">FontAwesome</a>
*/
@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);
}
} }

25
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.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; 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_DESCRIPTION;
import static gr.thmmy.mthmmy.activities.upload.UploadFieldsBuilderActivity.RESULT_FILENAME; 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.activities.upload.UploadFieldsBuilderActivity.RESULT_TITLE;
import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename;
public class UploadActivity extends BaseActivity { public class UploadActivity extends BaseActivity {
/** /**
@ -391,8 +393,9 @@ public class UploadActivity extends BaseActivity {
} }
String uploadID = UUID.randomUUID().toString(); String uploadID = UUID.randomUUID().toString();
if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID), categorySelected, if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID,
uploadTitleText, uploadDescriptionText[0], fileIcon, uploaderProfileIndex, editTextFilename), categorySelected, uploadTitleText,
uploadDescriptionText[0], fileIcon, uploaderProfileIndex,
tempFileUri == null tempFileUri == null
? filesList.get(0).getFileUri() ? filesList.get(0).getFileUri()
: tempFileUri)) { : tempFileUri)) {
@ -449,12 +452,8 @@ public class UploadActivity extends BaseActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING) if (parseUploadPageTask != null && parseUploadPageTask.getStatus() != AsyncTask.Status.RUNNING) {
parseUploadPageTask.cancel(true); 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); inflate(R.layout.activity_upload_file_list_row, null);
TextView itemText = newFileRow.findViewById(R.id.upload_file_item_text); TextView itemText = newFileRow.findViewById(R.id.upload_file_item_text);
Drawable filenameDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_attach_file_white_24dp); itemText.setTypeface(Typeface.createFromAsset(this.getAssets()
itemText.setCompoundDrawablesRelativeWithIntrinsicBounds(filenameDrawable, null, null, null); , "fonts/fontawesome-webfont.ttf"));
itemText.setText(filename); itemText.setText(faIconFromFilename(this, filename) + " " + filename);
newFileRow.findViewById(R.id.upload_file_item_remove). newFileRow.findViewById(R.id.upload_file_item_remove).
setOnClickListener(view -> { setOnClickListener(view -> {
@ -669,9 +668,10 @@ public class UploadActivity extends BaseActivity {
filesListView.setVisibility(View.VISIBLE); 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 uploadNotificationConfig = new UploadNotificationConfig();
uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload);
uploadNotificationConfig.setTitleForAllStatuses("Uploading " + filename);
uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload;
uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; 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; uploadNotificationConfig.getCancelled().iconColorResourceID = android.R.drawable.stat_sys_upload_done;
Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD); Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD);
//combinedActionsIntent.setAction(UploadsReceiver.ACTION_COMBINED_UPLOAD);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID);
uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context, uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context,
@ -1009,7 +1008,7 @@ public class UploadActivity extends BaseActivity {
String uploadID = UUID.randomUUID().toString(); String uploadID = UUID.randomUUID().toString();
if (!uploadFile(weakActivity.get(), uploadID, if (!uploadFile(weakActivity.get(), uploadID,
getConfigForUpload(weakActivity.get(), uploadID), categorySelected, getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected,
uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex, uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex,
zipFileUri)) { zipFileUri)) {
Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show();

4
app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java

@ -43,8 +43,8 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
switch (intentAction) { switch (intentAction) {
case ACTION_CANCEL_UPLOAD: case ACTION_CANCEL_UPLOAD:
String notificationID = intentBundle.getString(UPLOAD_ID_KEY); String uploadID = intentBundle.getString(UPLOAD_ID_KEY);
UploadService.stopUpload(notificationID); UploadService.stopUpload(uploadID);
break; break;
case ACTION_RETRY_UPLOAD: case ACTION_RETRY_UPLOAD:
//TODO //TODO

35
app/src/main/java/gr/thmmy/mthmmy/utils/FileUtils.java

@ -10,6 +10,8 @@ import android.webkit.MimeTypeMap;
import java.io.File; import java.io.File;
import gr.thmmy.mthmmy.R;
import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR;
public class FileUtils { public class FileUtils {
@ -82,4 +84,37 @@ public class FileUtils {
} }
return -1; return -1;
} }
/**
* Returns a String with a single FontAwesome typeface character corresponding to this file's
* extension.
*
* @param filename String with filename <b>containing file's extension</b>
* @return FontAwesome character according to file's type
* @see <a href="http://fontawesome.io/">FontAwesome</a>
*/
@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);
}
} }

4
app/src/main/res/drawable/ic_attach_file_white_24dp.xml

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<path android:fillColor="#FFFFFF" android:pathData="M16.5,6v11.5c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4V5c0,-1.38 1.12,-2.5 2.5,-2.5s2.5,1.12 2.5,2.5v10.5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6H10v9.5c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5V5c0,-2.21 -1.79,-4 -4,-4S7,2.79 7,5v12.5c0,3.04 2.46,5.5 5.5,5.5s5.5,-2.46 5.5,-5.5V6h-1.5z"/>
</vector>

1
app/src/main/res/layout/activity_upload_file_list_row.xml

@ -11,7 +11,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_weight="1" android:layout_weight="1"
android:drawablePadding="5dp"
android:ellipsize="marquee" android:ellipsize="marquee"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/primary_text" /> android:textColor="@color/primary_text" />

Loading…
Cancel
Save