Support URLs with path prefix (#46)
See gotify/server#127 gotify/server#122
This commit is contained in:
@@ -18,6 +18,10 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import okio.Buffer;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
|
||||
@@ -36,6 +40,22 @@ public class Utils {
|
||||
.toString();
|
||||
}
|
||||
|
||||
public static String resolveAbsoluteUrl(String baseURL, String target) {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
URI targetUri = new URI(target);
|
||||
if (targetUri.isAbsolute()) {
|
||||
return target;
|
||||
}
|
||||
return new URL(new URL(baseURL), target).toString();
|
||||
} catch (MalformedURLException | URISyntaxException e) {
|
||||
Log.e("Could not resolve absolute url", e);
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
public static Target toDrawable(Resources resources, DrawableReceiver drawableReceiver) {
|
||||
return new Target() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user