2017-11-04 08:17:31 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
package com.keylesspalace.tusky.util;
|
|
|
|
|
|
|
|
import android.arch.core.util.Function;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
|
|
|
import com.keylesspalace.tusky.entity.Notification;
|
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
|
|
|
import com.keylesspalace.tusky.viewdata.NotificationViewData;
|
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by charlag on 12/07/2017.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public final class ViewDataUtils {
|
|
|
|
@Nullable
|
2017-11-07 02:19:15 +11:00
|
|
|
public static StatusViewData.Concrete statusToViewData(@Nullable Status status) {
|
2017-07-13 05:54:52 +10:00
|
|
|
if (status == null) return null;
|
|
|
|
Status visibleStatus = status.reblog == null ? status : status.reblog;
|
2017-10-20 00:25:04 +11:00
|
|
|
return new StatusViewData.Builder().setId(status.id)
|
2017-07-15 21:57:51 +10:00
|
|
|
.setAttachments(visibleStatus.attachments)
|
2017-07-13 05:54:52 +10:00
|
|
|
.setAvatar(visibleStatus.account.avatar)
|
|
|
|
.setContent(visibleStatus.content)
|
|
|
|
.setCreatedAt(visibleStatus.createdAt)
|
2017-08-03 14:29:31 +10:00
|
|
|
.setReblogsCount(visibleStatus.reblogsCount)
|
|
|
|
.setFavouritesCount(visibleStatus.favouritesCount)
|
2017-08-04 12:30:37 +10:00
|
|
|
.setInReplyToId(visibleStatus.inReplyToId)
|
2017-07-13 05:54:52 +10:00
|
|
|
.setFavourited(visibleStatus.favourited)
|
|
|
|
.setReblogged(visibleStatus.reblogged)
|
|
|
|
.setIsExpanded(false)
|
|
|
|
.setIsShowingSensitiveContent(false)
|
|
|
|
.setMentions(visibleStatus.mentions)
|
|
|
|
.setNickname(visibleStatus.account.username)
|
2017-07-14 15:06:32 +10:00
|
|
|
.setRebloggedAvatar(status.reblog == null ? null : status.account.avatar)
|
2017-07-13 05:54:52 +10:00
|
|
|
.setSensitive(visibleStatus.sensitive)
|
|
|
|
.setSpoilerText(visibleStatus.spoilerText)
|
|
|
|
.setRebloggedByUsername(status.reblog == null ? null : status.account.username)
|
|
|
|
.setUserFullName(visibleStatus.account.getDisplayName())
|
2017-07-17 09:56:26 +10:00
|
|
|
.setVisibility(visibleStatus.visibility)
|
2017-07-15 21:57:51 +10:00
|
|
|
.setSenderId(visibleStatus.account.id)
|
2017-07-13 05:54:52 +10:00
|
|
|
.setRebloggingEnabled(visibleStatus.rebloggingAllowed())
|
2017-08-03 14:29:31 +10:00
|
|
|
.setApplication(visibleStatus.application)
|
2017-10-20 00:25:04 +11:00
|
|
|
.setEmojis(visibleStatus.emojis)
|
2017-07-13 05:54:52 +10:00
|
|
|
.createStatusViewData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<StatusViewData> statusListToViewDataList(List<Status> statuses) {
|
|
|
|
List<StatusViewData> viewDatas = new ArrayList<>(statuses.size());
|
|
|
|
for (Status s : statuses) {
|
|
|
|
viewDatas.add(statusToViewData(s));
|
|
|
|
}
|
|
|
|
return viewDatas;
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:19:15 +11:00
|
|
|
public static Function<Status, StatusViewData.Concrete> statusMapper() {
|
2017-07-13 05:54:52 +10:00
|
|
|
return statusMapper;
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:19:15 +11:00
|
|
|
public static NotificationViewData.Concrete notificationToViewData(Notification notification) {
|
2017-11-06 03:11:00 +11:00
|
|
|
return new NotificationViewData.Concrete(notification.type, notification.id, notification.account,
|
|
|
|
statusToViewData(notification.status));
|
2017-07-13 05:54:52 +10:00
|
|
|
}
|
|
|
|
|
2017-10-20 00:25:04 +11:00
|
|
|
public static List<NotificationViewData> notificationListToViewDataList(
|
|
|
|
List<Notification> notifications) {
|
2017-07-13 05:54:52 +10:00
|
|
|
List<NotificationViewData> viewDatas = new ArrayList<>(notifications.size());
|
|
|
|
for (Notification n : notifications) {
|
|
|
|
viewDatas.add(notificationToViewData(n));
|
|
|
|
}
|
|
|
|
return viewDatas;
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:19:15 +11:00
|
|
|
private static final Function<Status, StatusViewData.Concrete> statusMapper =
|
|
|
|
new Function<Status, StatusViewData.Concrete>() {
|
2017-07-13 05:54:52 +10:00
|
|
|
@Override
|
2017-11-07 02:19:15 +11:00
|
|
|
public StatusViewData.Concrete apply(Status input) {
|
2017-07-13 05:54:52 +10:00
|
|
|
return ViewDataUtils.statusToViewData(input);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|