use of com.sys1yagi.mastodon4j.api.entity.Attachment in project twicalico by moko256.
the class PostTweetModelImpl method postTweet.
@Override
public Single<Status> postTweet() {
return Single.create(subscriber -> {
try {
List<Long> ids = null;
if (uriList.size() > 0) {
ids = new ArrayList<>(uriList.size());
for (Uri uri : uriList) {
InputStream image = contentResolver.openInputStream(uri);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (true) {
int len = image.read(buffer);
if (len < 0) {
break;
}
bout.write(buffer, 0, len);
}
Attachment attachment = new Media(((MastodonTwitterImpl) GlobalApplication.twitter).client).postMedia(MultipartBody.Part.createFormData("file", uri.getLastPathSegment(), RequestBody.create(MediaType.parse(contentResolver.getType(uri)), bout.toByteArray()))).execute();
ids.add(attachment.getId());
}
}
subscriber.onSuccess(new MTStatus(new Statuses(client).postStatus(tweetText, inReplyToStatusId == -1 ? null : inReplyToStatusId, ids, possiblySensitive, null, com.sys1yagi.mastodon4j.api.entity.Status.Visibility.Public).execute()));
} catch (IOException | Mastodon4jRequestException e) {
subscriber.onError(e);
}
});
}
use of com.sys1yagi.mastodon4j.api.entity.Attachment in project twicalico by moko256.
the class MTStatus method getMediaEntities.
@Override
public MediaEntity[] getMediaEntities() {
List<Attachment> medias = status.getMediaAttachments();
MediaEntity[] mediaEntities = new MediaEntity[medias.size()];
for (int i = 0; i < mediaEntities.length; i++) {
Attachment media = medias.get(i);
mediaEntities[i] = new MTMediaEntity(media);
}
return mediaEntities;
}
Aggregations