From 3cbdaba3403bd26a1c9fb44e6a86efc84000efea Mon Sep 17 00:00:00 2001 From: Apostolof Date: Tue, 20 Dec 2016 22:52:48 +0200 Subject: [PATCH] Attachments finalization. --- .../activities/topic/TopicActivity.java | 3 +- .../mthmmy/activities/topic/TopicAdapter.java | 29 +++++++++++++++++-- .../mthmmy/activities/topic/TopicParser.java | 9 ++++-- app/src/main/res/values/strings.xml | 9 ++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 95f414ae..02b26ac7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -9,6 +9,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.os.Handler; +import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; @@ -476,7 +477,6 @@ public class TopicActivity extends BaseActivity { */ static void downloadFileAsync(final String downloadUrl, final String fileName, final Context context) { Request request = new Request.Builder().url(downloadUrl).build(); - //final File[] tmpFile = new File[1]; getClient().newCall(request).enqueue(new Callback() { public void onFailure(Call call, IOException e) { @@ -514,6 +514,7 @@ public class TopicActivity extends BaseActivity { /** * Create a File */ + @Nullable private static File getOutputMediaFile(String packageName, String fileName) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. 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 b74fef50..fd7cf4d4 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 @@ -10,6 +10,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; @@ -195,7 +196,6 @@ class TopicAdapter extends RecyclerView.Adapter { if (currentPost.getAttachedFiles().size() != 0) { holder.bodyFooterDivider.setVisibility(View.VISIBLE); - String faFile = context.getResources().getString(R.string.fa_file); int filesTextColor = context.getResources().getColor(R.color.accent); for (final String[] attachedFile : currentPost.getAttachedFiles()) { @@ -204,7 +204,7 @@ class TopicAdapter extends RecyclerView.Adapter { attached.setClickable(true); attached.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); - attached.setText(faFile + " " + attachedFile[1] + attachedFile[2]); + attached.setText(faIconFromExtension(attachedFile[1]) + " " + attachedFile[1] + attachedFile[2]); attached.setTextColor(filesTextColor); attached.setPadding(0, 3, 0, 3); @@ -547,4 +547,29 @@ class TopicAdapter extends RecyclerView.Adapter { } } //------------------------------------CUSTOM WEBVIEW CLIENT END------------------------------------- + + @NonNull + private String faIconFromExtension(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/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index 8d92e7d5..c327e0a8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.graphics.Color; +import android.util.Log; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -204,8 +205,10 @@ class TopicParser { //Get file's info (size and download count) String postAttachmentsTextSbstr = postAttachmentsText.substring( postAttachmentsText.indexOf(attachedArray[1])); + attachedArray[2] = postAttachmentsTextSbstr.substring(attachedArray[1].length() - , postAttachmentsTextSbstr.indexOf(postAttachedSubstr)); + , postAttachmentsTextSbstr.indexOf(postAttachedSubstr)) + + postAttachedSubstr + ")"; p_attachedFiles.add(attachedArray); } @@ -288,7 +291,7 @@ class TopicParser { final String en_userNameSelection = "View the profile of"; final String en_guestSelection = "Guest"; final String en_postAttachedDiv = "downloaded"; - final String en_postAttachedSubstr = "times.\\)"; + final String en_postAttachedSubstr = "times."; final String en_postsNumberSelection = "Reply #"; final String en_numberOfPostsSelection = "Posts:"; final String en_genderSelection = "Gender:"; @@ -301,7 +304,7 @@ class TopicParser { final String gr_userNameSelection = "Εμφάνιση προφίλ του μέλους"; final String gr_guestSelection = "Επισκέπτης"; final String gr_postAttachedDiv = "έγινε λήψη"; - final String gr_postAttachedSubstr = "φορές.\\)"; + final String gr_postAttachedSubstr = "φορές."; final String gr_postsNumberSelection = "Απάντηση #"; final String gr_numberOfPostsSelection = "Μηνύματα:"; final String gr_genderSelection = "Φύλο:"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e09cba8..136603b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,8 +25,17 @@ next last Home + + + + + + + + + #%1$d