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.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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by charlag on 12/07/2017.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public final class ViewDataUtils {
|
|
|
|
@Nullable
|
2017-12-01 06:12:09 +11:00
|
|
|
public static StatusViewData.Concrete statusToViewData(@Nullable Status status,
|
|
|
|
boolean alwaysShowSensitiveMedia) {
|
2017-07-13 05:54:52 +10:00
|
|
|
if (status == null) return null;
|
2018-03-03 23:24:03 +11:00
|
|
|
Status visibleStatus = status.getReblog() == null ? status : status.getReblog();
|
|
|
|
return new StatusViewData.Builder().setId(status.getId())
|
|
|
|
.setAttachments(visibleStatus.getAttachments())
|
|
|
|
.setAvatar(visibleStatus.getAccount().getAvatar())
|
|
|
|
.setContent(visibleStatus.getContent())
|
|
|
|
.setCreatedAt(visibleStatus.getCreatedAt())
|
|
|
|
.setReblogsCount(visibleStatus.getReblogsCount())
|
|
|
|
.setFavouritesCount(visibleStatus.getFavouritesCount())
|
|
|
|
.setInReplyToId(visibleStatus.getInReplyToId())
|
|
|
|
.setFavourited(visibleStatus.getFavourited())
|
|
|
|
.setReblogged(visibleStatus.getReblogged())
|
2017-07-13 05:54:52 +10:00
|
|
|
.setIsExpanded(false)
|
|
|
|
.setIsShowingSensitiveContent(false)
|
2018-03-03 23:24:03 +11:00
|
|
|
.setMentions(visibleStatus.getMentions())
|
|
|
|
.setNickname(visibleStatus.getAccount().getUsername())
|
|
|
|
.setRebloggedAvatar(status.getReblog() == null ? null : status.getAccount().getAvatar())
|
|
|
|
.setSensitive(visibleStatus.getSensitive())
|
|
|
|
.setIsShowingSensitiveContent(alwaysShowSensitiveMedia || !visibleStatus.getSensitive())
|
|
|
|
.setSpoilerText(visibleStatus.getSpoilerText())
|
|
|
|
.setRebloggedByUsername(status.getReblog() == null ? null : status.getAccount().getUsername())
|
|
|
|
.setUserFullName(visibleStatus.getAccount().getName())
|
|
|
|
.setVisibility(visibleStatus.getVisibility())
|
|
|
|
.setSenderId(visibleStatus.getAccount().getId())
|
2017-07-13 05:54:52 +10:00
|
|
|
.setRebloggingEnabled(visibleStatus.rebloggingAllowed())
|
2018-03-03 23:24:03 +11:00
|
|
|
.setApplication(visibleStatus.getApplication())
|
|
|
|
.setEmojis(visibleStatus.getEmojis())
|
2017-07-13 05:54:52 +10:00
|
|
|
.createStatusViewData();
|
|
|
|
}
|
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
public static NotificationViewData.Concrete notificationToViewData(Notification notification, boolean alwaysShowSensitiveData) {
|
2018-03-03 23:24:03 +11:00
|
|
|
return new NotificationViewData.Concrete(notification.getType(), notification.getId(), notification.getAccount(),
|
|
|
|
statusToViewData(notification.getStatus(), alwaysShowSensitiveData), false);
|
2017-07-13 05:54:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|