diff --git a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/Attachment.java b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/Attachment.java index 8fb8733..82bf80c 100644 --- a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/Attachment.java +++ b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/Attachment.java @@ -5,5 +5,6 @@ */ public class Attachment { public String name; + public String type; public String url; } diff --git a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/AttachmentsAdapter.java b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/AttachmentsAdapter.java index 5985f6b..3f16408 100644 --- a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/AttachmentsAdapter.java +++ b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/AttachmentsAdapter.java @@ -1,8 +1,14 @@ package com.macbitsgoa.comrades.csa; +import android.app.DownloadManager; +import android.content.Context; +import android.graphics.Color; +import android.net.Uri; +import android.os.Environment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.MimeTypeMap; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; @@ -15,9 +21,11 @@ public class AttachmentsAdapter extends RecyclerView.Adapter { private List attachments; + private Context context; - public AttachmentsAdapter(final List attachments) { + public AttachmentsAdapter(final List attachments, Context context) { this.attachments = attachments; + this.context = context; } @Override @@ -40,15 +48,73 @@ public class AttachmentsVH extends RecyclerView.ViewHolder { private TextView filenameTv; private SimpleDraweeView fileThumbSdv; + + public AttachmentsVH(View itemView) { super(itemView); filenameTv = itemView.findViewById(R.id.tv_filename); fileThumbSdv = itemView.findViewById(R.id.sdv_file_thumb); + } - void populateFile(Attachment attachment) { + void populateFile(Attachment attachment) + { filenameTv.setText(attachment.name); - fileThumbSdv.setImageURI(attachment.url); + + if(attachment.type.equalsIgnoreCase("image")) + { + fileThumbSdv.setImageURI(attachment.url); + } + else if(attachment.type.equalsIgnoreCase("pdf")) + { + fileThumbSdv.setImageResource(R.drawable.ic_pdf_black_24dp); + fileThumbSdv.setColorFilter(Color.parseColor("#F44336")); + } + else if(attachment.type.equalsIgnoreCase("doc")) + { + fileThumbSdv.setImageResource(R.drawable.icon_doc); + fileThumbSdv.setColorFilter(Color.parseColor("#56ABE4")); + } + else if (attachment.type.equalsIgnoreCase("ppt")) + { + fileThumbSdv.setImageResource(R.drawable.icon_ppt); + fileThumbSdv.setColorFilter(Color.parseColor("#f39c12")); + } + else if(attachment.type.equalsIgnoreCase("sheet")) + { + fileThumbSdv.setImageResource(R.drawable.icon_xls); + fileThumbSdv.setColorFilter(Color.parseColor("#008000")); + } + + fileThumbSdv.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DownloadManager downloadManager =(DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE); + Uri uri = Uri.parse(attachment.url); + DownloadManager.Request request = new DownloadManager.Request(uri); + request.setVisibleInDownloadsUi(true); + request.setTitle("Attachment"); + request.setDescription(""+attachment.name); + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + request.setMimeType(getMimeType(uri.toString())); + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, + "/Comrades CSA Media/"+attachment.name+"."+MimeTypeMap.getFileExtensionFromUrl(uri.toString())); + Long ref = downloadManager.enqueue(request); + } + }); } + + private String getMimeType(String url) { + String type = null; + String extension = MimeTypeMap.getFileExtensionFromUrl(url); + if (extension != null) { + MimeTypeMap mime = MimeTypeMap.getSingleton(); + type = mime.getMimeTypeFromExtension(extension); + } + return type; + } + + + } } diff --git a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaMsgDetailActivity.java b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaMsgDetailActivity.java index 322b6b7..2ddbf8b 100644 --- a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaMsgDetailActivity.java +++ b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaMsgDetailActivity.java @@ -27,6 +27,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { CsaNews news = new Gson().fromJson(getIntent().getStringExtra(EXTRA_KEY_NEWS), CsaNews.class); + final TextView titleTv = findViewById(R.id.Heading); final TextView contentTv = findViewById(R.id.content_csa_msg); final TextView nameTv = findViewById(R.id.sender_name); @@ -45,8 +46,12 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { contentTv.setText(news.content); timestampTv.setText(news.timestamp); - final AttachmentsAdapter attachmentsAdapter = new AttachmentsAdapter(news.attachment); - attachList.setAdapter(attachmentsAdapter); - dpSdv.setImageURI(news.profileImageUrl); + if(news.attachment!=null) + { + final AttachmentsAdapter attachmentsAdapter = new AttachmentsAdapter(news.attachment,this); + attachList.setAdapter(attachmentsAdapter); + } + dpSdv.setImageURI(news.profileImageURL); + } } diff --git a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaNews.java b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaNews.java index 9b8d23e..766839f 100644 --- a/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaNews.java +++ b/androidClient/app/src/main/java/com/macbitsgoa/comrades/csa/CsaNews.java @@ -8,7 +8,7 @@ public class CsaNews { public String post; public String content; public String timestamp; - public String profileImageUrl; + public String profileImageURL; public List attachment; public boolean notify; } diff --git a/androidClient/app/src/main/res/drawable/icon_doc.png b/androidClient/app/src/main/res/drawable/icon_doc.png new file mode 100644 index 0000000..e4c84e5 Binary files /dev/null and b/androidClient/app/src/main/res/drawable/icon_doc.png differ diff --git a/androidClient/app/src/main/res/drawable/icon_ppt.png b/androidClient/app/src/main/res/drawable/icon_ppt.png new file mode 100644 index 0000000..9edd183 Binary files /dev/null and b/androidClient/app/src/main/res/drawable/icon_ppt.png differ diff --git a/androidClient/app/src/main/res/drawable/icon_xls.png b/androidClient/app/src/main/res/drawable/icon_xls.png new file mode 100644 index 0000000..aedc8ff Binary files /dev/null and b/androidClient/app/src/main/res/drawable/icon_xls.png differ diff --git a/androidClient/app/src/main/res/drawable/pdf-icon.png b/androidClient/app/src/main/res/drawable/pdf-icon.png new file mode 100644 index 0000000..61fa922 Binary files /dev/null and b/androidClient/app/src/main/res/drawable/pdf-icon.png differ diff --git a/androidClient/app/src/main/res/drawable/pdf_icon.png b/androidClient/app/src/main/res/drawable/pdf_icon.png new file mode 100644 index 0000000..61fa922 Binary files /dev/null and b/androidClient/app/src/main/res/drawable/pdf_icon.png differ diff --git a/androidClient/app/src/main/res/layout/activity_csa_msg_detail.xml b/androidClient/app/src/main/res/layout/activity_csa_msg_detail.xml index e0c513e..56c031b 100644 --- a/androidClient/app/src/main/res/layout/activity_csa_msg_detail.xml +++ b/androidClient/app/src/main/res/layout/activity_csa_msg_detail.xml @@ -58,6 +58,8 @@ android:id="@+id/profile_dp" android:layout_width="75dp" android:layout_height="75dp" + app:placeholderImage="@drawable/ic_person_black_24dp" + app:placeholderImageScaleType="fitCenter" app:roundAsCircle="true" android:layout_margin="5dp"/> diff --git a/androidClient/app/src/main/res/layout/vh_attachment.xml b/androidClient/app/src/main/res/layout/vh_attachment.xml index 0fe3e4d..a4b13fb 100644 --- a/androidClient/app/src/main/res/layout/vh_attachment.xml +++ b/androidClient/app/src/main/res/layout/vh_attachment.xml @@ -1,33 +1,40 @@ - + app:cardElevation="5dp" + android:layout_margin="10dp"> - - - - + android:padding="10dp" + android:orientation="vertical"> + + + + + + - +