Browse Source

Attachments finalization.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
3cbdaba340
  1. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 29
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  4. 9
      app/src/main/res/values/strings.xml

3
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.

29
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<TopicAdapter.MyViewHolder> {
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<TopicAdapter.MyViewHolder> {
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<TopicAdapter.MyViewHolder> {
}
}
//------------------------------------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);
}
}

9
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 = "Φύλο:";

9
app/src/main/res/values/strings.xml

@ -25,8 +25,17 @@
<string name="text_next">next</string>
<string name="text_last">last</string>
<string name="home">Home</string>
<string name="fa_icon_star">&#xf005;</string>
<string name="fa_file">&#xf15b;</string>
<string name="fa_file_image_o">&#xf1c5;</string>
<string name="fa_file_pdf_o">&#xf1c1;</string>
<string name="fa_file_zip_o">&#xf1c6;</string>
<string name="fa_file_text_o">&#xf0f6;</string>
<string name="fa_file_word_o">&#xf1c2;</string>
<string name="fa_file_powerpoint_o">&#xf1c4;</string>
<string name="fa_file_excel_o">&#xf1c3;</string>
<string name="fa_file_video_o">&#xf1c8;</string>
<string name="user_number_of_posts">#%1$d</string>
</resources>

Loading…
Cancel
Save