|
|
@ -21,9 +21,12 @@ import android.support.v7.widget.RecyclerView; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.android.volley.toolbox.NetworkImageView; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -36,14 +39,16 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe |
|
|
|
|
|
|
|
|
|
|
|
private List<Notification> notifications; |
|
|
|
private List<Notification> notifications; |
|
|
|
private StatusActionListener statusListener; |
|
|
|
private StatusActionListener statusListener; |
|
|
|
|
|
|
|
private FollowListener followListener; |
|
|
|
private FooterActionListener footerListener; |
|
|
|
private FooterActionListener footerListener; |
|
|
|
private FooterViewHolder.State footerState; |
|
|
|
private FooterViewHolder.State footerState; |
|
|
|
|
|
|
|
|
|
|
|
NotificationsAdapter(StatusActionListener statusListener, |
|
|
|
NotificationsAdapter(StatusActionListener statusListener, FollowListener followListener, |
|
|
|
FooterActionListener footerListener) { |
|
|
|
FooterActionListener footerListener) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
notifications = new ArrayList<>(); |
|
|
|
notifications = new ArrayList<>(); |
|
|
|
this.statusListener = statusListener; |
|
|
|
this.statusListener = statusListener; |
|
|
|
|
|
|
|
this.followListener = followListener; |
|
|
|
this.footerListener = footerListener; |
|
|
|
this.footerListener = footerListener; |
|
|
|
footerState = FooterViewHolder.State.LOADING; |
|
|
|
footerState = FooterViewHolder.State.LOADING; |
|
|
|
} |
|
|
|
} |
|
|
@ -96,7 +101,10 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe |
|
|
|
} |
|
|
|
} |
|
|
|
case FOLLOW: { |
|
|
|
case FOLLOW: { |
|
|
|
FollowViewHolder holder = (FollowViewHolder) viewHolder; |
|
|
|
FollowViewHolder holder = (FollowViewHolder) viewHolder; |
|
|
|
holder.setMessage(notification.getDisplayName()); |
|
|
|
holder.setMessage(notification.getDisplayName(), notification.getUsername(), |
|
|
|
|
|
|
|
notification.getAvatar()); |
|
|
|
|
|
|
|
holder.setupButtons(followListener, notification.getAccountId(), |
|
|
|
|
|
|
|
notification.getUsername()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -177,19 +185,59 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe |
|
|
|
footerState = state; |
|
|
|
footerState = state; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface FollowListener { |
|
|
|
|
|
|
|
void onViewAccount(String id, String username); |
|
|
|
|
|
|
|
void onFollow(String id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class FollowViewHolder extends RecyclerView.ViewHolder { |
|
|
|
private static class FollowViewHolder extends RecyclerView.ViewHolder { |
|
|
|
private TextView message; |
|
|
|
private TextView message; |
|
|
|
|
|
|
|
private TextView usernameView; |
|
|
|
|
|
|
|
private TextView displayNameView; |
|
|
|
|
|
|
|
private NetworkImageView avatar; |
|
|
|
|
|
|
|
private Button follow; |
|
|
|
|
|
|
|
|
|
|
|
FollowViewHolder(View itemView) { |
|
|
|
FollowViewHolder(View itemView) { |
|
|
|
super(itemView); |
|
|
|
super(itemView); |
|
|
|
message = (TextView) itemView.findViewById(R.id.notification_text); |
|
|
|
message = (TextView) itemView.findViewById(R.id.notification_text); |
|
|
|
|
|
|
|
usernameView = (TextView) itemView.findViewById(R.id.notification_username); |
|
|
|
|
|
|
|
displayNameView = (TextView) itemView.findViewById(R.id.notification_display_name); |
|
|
|
|
|
|
|
avatar = (NetworkImageView) itemView.findViewById(R.id.notification_avatar); |
|
|
|
|
|
|
|
avatar.setDefaultImageResId(R.drawable.avatar_default); |
|
|
|
|
|
|
|
avatar.setErrorImageResId(R.drawable.avatar_error); |
|
|
|
|
|
|
|
follow = (Button) itemView.findViewById(R.id.notification_follow_button); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setMessage(String displayName) { |
|
|
|
void setMessage(String displayName, String username, String avatarUrl) { |
|
|
|
Context context = message.getContext(); |
|
|
|
Context context = message.getContext(); |
|
|
|
|
|
|
|
|
|
|
|
String format = context.getString(R.string.notification_follow_format); |
|
|
|
String format = context.getString(R.string.notification_follow_format); |
|
|
|
String wholeMessage = String.format(format, displayName); |
|
|
|
String wholeMessage = String.format(format, displayName); |
|
|
|
message.setText(wholeMessage); |
|
|
|
message.setText(wholeMessage); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
format = context.getString(R.string.status_username_format); |
|
|
|
|
|
|
|
String wholeUsername = String.format(format, username); |
|
|
|
|
|
|
|
usernameView.setText(wholeUsername); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
displayNameView.setText(displayName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avatar.setImageUrl(avatarUrl, VolleySingleton.getInstance(context).getImageLoader()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setupButtons(final FollowListener listener, final String accountId, |
|
|
|
|
|
|
|
final String username) { |
|
|
|
|
|
|
|
avatar.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
listener.onViewAccount(accountId, username); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
follow.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
listener.onFollow(accountId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|