Hide unknown notifications (#1151)
* hide unknown notifications * hide unknown notifications
This commit is contained in:
parent
c3df44eaef
commit
2e52457b32
2 changed files with 32 additions and 17 deletions
|
@ -45,6 +45,7 @@ import com.keylesspalace.tusky.util.LinkHelper;
|
||||||
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
import com.keylesspalace.tusky.util.SmartLengthInputFilter;
|
||||||
import com.keylesspalace.tusky.viewdata.NotificationViewData;
|
import com.keylesspalace.tusky.viewdata.NotificationViewData;
|
||||||
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
||||||
|
import com.mikepenz.iconics.utils.Utils;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -71,8 +72,9 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
private static final int VIEW_TYPE_STATUS_NOTIFICATION = 1;
|
private static final int VIEW_TYPE_STATUS_NOTIFICATION = 1;
|
||||||
private static final int VIEW_TYPE_FOLLOW = 2;
|
private static final int VIEW_TYPE_FOLLOW = 2;
|
||||||
private static final int VIEW_TYPE_PLACEHOLDER = 3;
|
private static final int VIEW_TYPE_PLACEHOLDER = 3;
|
||||||
|
private static final int VIEW_TYPE_UNKNOWN = 4;
|
||||||
|
|
||||||
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[] { SmartLengthInputFilter.INSTANCE };
|
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
|
||||||
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
|
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
|
||||||
|
|
||||||
private StatusActionListener statusListener;
|
private StatusActionListener statusListener;
|
||||||
|
@ -98,7 +100,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
default:
|
|
||||||
case VIEW_TYPE_MENTION: {
|
case VIEW_TYPE_MENTION: {
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.item_status, parent, false);
|
.inflate(R.layout.item_status, parent, false);
|
||||||
|
@ -119,25 +120,36 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
.inflate(R.layout.item_status_placeholder, parent, false);
|
.inflate(R.layout.item_status_placeholder, parent, false);
|
||||||
return new PlaceholderViewHolder(view);
|
return new PlaceholderViewHolder(view);
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
case VIEW_TYPE_UNKNOWN: {
|
||||||
|
View view = new View(parent.getContext());
|
||||||
|
view.setLayoutParams(
|
||||||
|
new ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
Utils.convertDpToPx(parent.getContext(), 24)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return new RecyclerView.ViewHolder(view) {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
bindViewHolder(viewHolder,position,null);
|
bindViewHolder(viewHolder, position, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @NonNull List payloads) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @NonNull List payloads) {
|
||||||
bindViewHolder(viewHolder,position,payloads);
|
bindViewHolder(viewHolder, position, payloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @Nullable List payloads){
|
private void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @Nullable List payloads) {
|
||||||
Object payloadForHolder = payloads!=null&&!payloads.isEmpty()?payloads.get(0):null;
|
Object payloadForHolder = payloads != null && !payloads.isEmpty() ? payloads.get(0) : null;
|
||||||
if (position < this.dataSource.getItemCount()) {
|
if (position < this.dataSource.getItemCount()) {
|
||||||
NotificationViewData notification = dataSource.getItemAt(position);
|
NotificationViewData notification = dataSource.getItemAt(position);
|
||||||
if (notification instanceof NotificationViewData.Placeholder) {
|
if (notification instanceof NotificationViewData.Placeholder) {
|
||||||
if (payloadForHolder==null) {
|
if (payloadForHolder == null) {
|
||||||
NotificationViewData.Placeholder placeholder = ((NotificationViewData.Placeholder) notification);
|
NotificationViewData.Placeholder placeholder = ((NotificationViewData.Placeholder) notification);
|
||||||
PlaceholderViewHolder holder = (PlaceholderViewHolder) viewHolder;
|
PlaceholderViewHolder holder = (PlaceholderViewHolder) viewHolder;
|
||||||
holder.setup(statusListener, placeholder.isLoading());
|
holder.setup(statusListener, placeholder.isLoading());
|
||||||
|
@ -148,19 +160,18 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
(NotificationViewData.Concrete) notification;
|
(NotificationViewData.Concrete) notification;
|
||||||
Notification.Type type = concreteNotificaton.getType();
|
Notification.Type type = concreteNotificaton.getType();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
|
||||||
case MENTION: {
|
case MENTION: {
|
||||||
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
||||||
StatusViewData.Concrete status = concreteNotificaton.getStatusViewData();
|
StatusViewData.Concrete status = concreteNotificaton.getStatusViewData();
|
||||||
holder.setupWithStatus(status,
|
holder.setupWithStatus(status,
|
||||||
statusListener, mediaPreviewEnabled,payloadForHolder);
|
statusListener, mediaPreviewEnabled, payloadForHolder);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FAVOURITE:
|
case FAVOURITE:
|
||||||
case REBLOG: {
|
case REBLOG: {
|
||||||
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
|
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
|
||||||
StatusViewData.Concrete statusViewData = concreteNotificaton.getStatusViewData();
|
StatusViewData.Concrete statusViewData = concreteNotificaton.getStatusViewData();
|
||||||
if (payloadForHolder==null) {
|
if (payloadForHolder == null) {
|
||||||
if (statusViewData == null) {
|
if (statusViewData == null) {
|
||||||
holder.showNotificationContent(false);
|
holder.showNotificationContent(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,11 +189,10 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
holder.setupButtons(notificationActionListener,
|
holder.setupButtons(notificationActionListener,
|
||||||
concreteNotificaton.getAccount().getId(),
|
concreteNotificaton.getAccount().getId(),
|
||||||
concreteNotificaton.getId());
|
concreteNotificaton.getId());
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
if (payloadForHolder instanceof List)
|
if (payloadForHolder instanceof List)
|
||||||
for (Object item:payloads) {
|
for (Object item : payloads) {
|
||||||
if (StatusBaseViewHolder.Key.KEY_CREATED.equals(item)){
|
if (StatusBaseViewHolder.Key.KEY_CREATED.equals(item)) {
|
||||||
holder.setCreatedAt(statusViewData.getCreatedAt());
|
holder.setCreatedAt(statusViewData.getCreatedAt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,17 +200,19 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOLLOW: {
|
case FOLLOW: {
|
||||||
if (payloadForHolder==null) {
|
if (payloadForHolder == null) {
|
||||||
FollowViewHolder holder = (FollowViewHolder) viewHolder;
|
FollowViewHolder holder = (FollowViewHolder) viewHolder;
|
||||||
holder.setMessage(concreteNotificaton.getAccount(), bidiFormatter);
|
holder.setMessage(concreteNotificaton.getAccount(), bidiFormatter);
|
||||||
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId());
|
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return dataSource.getItemCount();
|
return dataSource.getItemCount();
|
||||||
|
@ -212,7 +224,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
if (notification instanceof NotificationViewData.Concrete) {
|
if (notification instanceof NotificationViewData.Concrete) {
|
||||||
NotificationViewData.Concrete concrete = ((NotificationViewData.Concrete) notification);
|
NotificationViewData.Concrete concrete = ((NotificationViewData.Concrete) notification);
|
||||||
switch (concrete.getType()) {
|
switch (concrete.getType()) {
|
||||||
default:
|
|
||||||
case MENTION: {
|
case MENTION: {
|
||||||
return VIEW_TYPE_MENTION;
|
return VIEW_TYPE_MENTION;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +234,9 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
||||||
case FOLLOW: {
|
case FOLLOW: {
|
||||||
return VIEW_TYPE_FOLLOW;
|
return VIEW_TYPE_FOLLOW;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
|
return VIEW_TYPE_UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (notification instanceof NotificationViewData.Placeholder) {
|
} else if (notification instanceof NotificationViewData.Placeholder) {
|
||||||
return VIEW_TYPE_PLACEHOLDER;
|
return VIEW_TYPE_PLACEHOLDER;
|
||||||
|
|
|
@ -476,7 +476,6 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (notification.getType()) {
|
switch (notification.getType()) {
|
||||||
default:
|
|
||||||
case MENTION:
|
case MENTION:
|
||||||
return account.getNotificationsMentioned();
|
return account.getNotificationsMentioned();
|
||||||
case FOLLOW:
|
case FOLLOW:
|
||||||
|
@ -485,6 +484,8 @@ public class NotificationHelper {
|
||||||
return account.getNotificationsReblogged();
|
return account.getNotificationsReblogged();
|
||||||
case FAVOURITE:
|
case FAVOURITE:
|
||||||
return account.getNotificationsFavorited();
|
return account.getNotificationsFavorited();
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue