import net.pterodactylus.sone.data.TemporaryImage;
import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.database.DatabaseException;
+import net.pterodactylus.sone.database.ImageBuilder.ImageCreated;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostBuilder.PostCreated;
import net.pterodactylus.sone.database.PostProvider;
logger.log(Level.WARNING, "Invalid album image encountered, aborting load!");
return;
}
- album.newImageBuilder().withId(imageId).created(creationTime).at(key).sized(width, height).build().modify().setTitle(title).setDescription(description).update();
+ album.newImageBuilder().withId(imageId).created(creationTime).at(key).sized(width, height).build(Optional.<ImageCreated>absent()).modify().setTitle(title).setDescription(description).update();
}
/* load avatar. */
checkNotNull(temporaryImage, "temporaryImage must not be null");
checkArgument(sone.isLocal(), "sone must be a local Sone");
checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
- Image image = album.newImageBuilder().withId(temporaryImage.getId()).sized(temporaryImage.getWidth(), temporaryImage.getHeight()).build();
+ Image image = album.newImageBuilder().withId(temporaryImage.getId()).sized(temporaryImage.getWidth(), temporaryImage.getHeight()).build(imageCreated());
imageInserter.insertImage(temporaryImage, image);
return image;
}
});
}
+ public Optional<ImageCreated> imageCreated() {
+ return Optional.<ImageCreated>of(new ImageCreated() {
+ @Override
+ public void imageCreated(Image image) {
+ /* nothing happens here yet. */
+ }
+ });
+ }
+
}
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.data.impl.DefaultSone;
+import net.pterodactylus.sone.database.ImageBuilder.ImageCreated;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostBuilder.PostCreated;
import net.pterodactylus.sone.database.PostReplyBuilder;
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
return null;
}
- Image image = album.newImageBuilder().withId(imageId).at(imageKey).created(creationTime).sized(imageWidth, imageHeight).build();
+ Image image = album.newImageBuilder().withId(imageId).at(imageKey).created(creationTime).sized(imageWidth, imageHeight).build(Optional.<ImageCreated>absent());
image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
}
}
public ImageBuilder newImageBuilder() throws IllegalStateException {
return new AbstractImageBuilder() {
@Override
- public Image build() throws IllegalStateException {
+ public Image build(Optional<ImageCreated> imageCreated) throws IllegalStateException {
validate();
- DefaultImage memoryImage = new DefaultImage(database, getId(), sone, DefaultAlbum.this.id, key, getCreationTime(), width, height);
- database.storeImage(memoryImage);
- return memoryImage;
+ DefaultImage image = new DefaultImage(database, getId(), sone, DefaultAlbum.this.id, key, getCreationTime(), width, height);
+ database.storeImage(image);
+ if (imageCreated.isPresent()) {
+ imageCreated.get().imageCreated(image);
+ }
+ return image;
}
};
}
import net.pterodactylus.sone.data.Image;
+import com.google.common.base.Optional;
+
/**
* Builder for {@link Image} objects.
*
ImageBuilder at(String key);
ImageBuilder sized(int width, int height);
- Image build() throws IllegalStateException;
+ Image build(Optional<ImageCreated> imageCreated) throws IllegalStateException;
+
+ interface ImageCreated {
+
+ void imageCreated(Image image);
+
+ }
}