Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
*/
public class Attachment {
public String name;
public String type;
public String url;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,9 +21,11 @@
public class AttachmentsAdapter extends RecyclerView.Adapter<AttachmentsAdapter.AttachmentsVH> {

private List<Attachment> attachments;
private Context context;

public AttachmentsAdapter(final List<Attachment> attachments) {
public AttachmentsAdapter(final List<Attachment> attachments, Context context) {
this.attachments = attachments;
this.context = context;
}

@Override
Expand All @@ -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;
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> attachment;
public boolean notify;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand Down
55 changes: 31 additions & 24 deletions androidClient/app/src/main/res/layout/vh_attachment.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp">
app:cardElevation="5dp"
android:layout_margin="10dp">


<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_file_thumb"
android:layout_width="300dp"
app:placeholderImage="@drawable/ic_photo_black_24dp"
android:layout_gravity="center"
android:layout_height="200dp" />

<TextView
android:id="@+id/tv_filename"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Poster for Random Event"
android:textSize="21sp"
android:padding="5dp"
android:fontFamily="@font/ps_regular"
android:layout_marginStart="2dp"
android:layout_gravity="center"
android:textColor="@color/black"/>
android:padding="10dp"
android:orientation="vertical">

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_file_thumb"
android:layout_width="280dp"
app:placeholderImage="@drawable/ic_file"
app:placeholderImageScaleType="fitCenter"
android:scaleType="fitCenter"
android:layout_gravity="center"
android:layout_height="185dp" />

<TextView
android:id="@+id/tv_filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Poster for Random Event"
android:textSize="21sp"
android:padding="5dp"
android:fontFamily="@font/ps_regular"
android:layout_marginStart="2dp"
android:layout_gravity="center"
android:textColor="@color/black"/>

</LinearLayout>

</LinearLayout>
</com.google.android.material.card.MaterialCardView>