app/src/main/java/com/larryhsiao/nyx/attachment/JotImageLoading.java
package com.larryhsiao.nyx.attachment;
import android.widget.ImageView;
import com.larryhsiao.aura.uri.UriMimeType;
import com.larryhsiao.clotho.Action;
/**
* Action to load up a Image from Jot Uri.
* It will load a remote image at Firestore if the Uri is generated by Jotted
* and not exist at local.
*/
public class JotImageLoading implements Action {
private final ImageView img;
private final String uri;
private final int progressColor;
public JotImageLoading(ImageView img, String uri, int progressColor) {
this.img = img;
this.uri = uri;
this.progressColor = progressColor;
}
@Override
public void fire() {
if (uri.startsWith("http")) {
new HttpPreviewLoading(img, uri).fire();
} else {
final String mediaType =
new UriMimeType(img.getContext(), uri).value();
if (mediaType.startsWith("image")) {
new ImageLoading(img, uri, progressColor).fire();
} else if (mediaType.startsWith("video")) {
new VideoPreviewLoading(img, uri).fire();
} else if (mediaType.startsWith("audio")) {
new AudioImageLoading(img, uri).fire();
} else {
new ImageLoading(img, uri, progressColor).fire();
}
}
}
}