|
@@ -20,8 +20,11 @@
|
|
|
package com.owncloud.android.ui.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Typeface;
|
|
|
import android.graphics.drawable.PictureDrawable;
|
|
|
import android.net.Uri;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
@@ -47,8 +50,11 @@ import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+
|
|
|
/**
|
|
|
- * This Adapter populates a ListView with all notifications for an account within the app.
|
|
|
+ * This Adapter populates a RecyclerView with all notifications for an account within the app.
|
|
|
*/
|
|
|
public class NotificationListAdapter extends RecyclerView.Adapter<NotificationListAdapter.NotificationViewHolder> {
|
|
|
private List<Notification> mValues;
|
|
@@ -65,17 +71,26 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|
|
notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
+ @NonNull
|
|
|
@Override
|
|
|
- public NotificationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
+ public NotificationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_list_item, parent, false);
|
|
|
return new NotificationViewHolder(v);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onBindViewHolder(NotificationViewHolder holder, int position) {
|
|
|
+ public void onBindViewHolder(@NonNull NotificationViewHolder holder, int position) {
|
|
|
Notification notification = mValues.get(position);
|
|
|
holder.dateTime.setText(DisplayUtils.getRelativeTimestamp(context, notification.getDatetime().getTime()));
|
|
|
- holder.subject.setText(notification.getSubject());
|
|
|
+
|
|
|
+ String subject = notification.getSubject();
|
|
|
+ if (!TextUtils.isEmpty(notification.getLink())) {
|
|
|
+ subject = subject + " ↗";
|
|
|
+ holder.subject.setTypeface(holder.subject.getTypeface(), Typeface.BOLD);
|
|
|
+ holder.subject.setOnClickListener(v -> openLink(notification.getLink()));
|
|
|
+ }
|
|
|
+
|
|
|
+ holder.subject.setText(subject);
|
|
|
holder.message.setText(notification.getMessage());
|
|
|
|
|
|
// Todo set proper action icon (to be clarified how to pick)
|
|
@@ -107,23 +122,28 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|
|
.into(itemViewType);
|
|
|
}
|
|
|
|
|
|
+ private void openLink(String link) {
|
|
|
+ context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int getItemCount() {
|
|
|
return mValues.size();
|
|
|
}
|
|
|
|
|
|
static class NotificationViewHolder extends RecyclerView.ViewHolder {
|
|
|
- private final ImageView activityIcon;
|
|
|
- private final TextView subject;
|
|
|
- private final TextView message;
|
|
|
- private final TextView dateTime;
|
|
|
+ @BindView(R.id.activity_icon)
|
|
|
+ public ImageView activityIcon;
|
|
|
+ @BindView(R.id.activity_subject)
|
|
|
+ public TextView subject;
|
|
|
+ @BindView(R.id.activity_message)
|
|
|
+ public TextView message;
|
|
|
+ @BindView(R.id.activity_datetime)
|
|
|
+ public TextView dateTime;
|
|
|
|
|
|
private NotificationViewHolder(View itemView) {
|
|
|
super(itemView);
|
|
|
- activityIcon = (ImageView) itemView.findViewById(R.id.activity_icon);
|
|
|
- subject = (TextView) itemView.findViewById(R.id.activity_subject);
|
|
|
- message = (TextView) itemView.findViewById(R.id.activity_message);
|
|
|
- dateTime = (TextView) itemView.findViewById(R.id.activity_datetime);
|
|
|
+ ButterKnife.bind(this, itemView);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|