Merge pull request #955 from maskaravivek/fixNpe

Fixes NPE in Util function
This commit is contained in:
neslihanturan 2017-11-17 15:02:39 +03:00 committed by GitHub
commit 461ca3add6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View file

@ -120,8 +120,9 @@ public class Media implements Parcelable {
return localUri;
}
@Nullable
public String getImageUrl() {
if (imageUrl == null) {
if (imageUrl == null && this.getFilename() != null) {
imageUrl = Utils.makeThumbBaseUrl(this.getFilename());
}
return imageUrl;

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons;
import android.content.Context;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.text.Html;
import android.text.Spanned;
@ -127,7 +128,7 @@ public class Utils {
return isoFormat.format(date);
}
public static String makeThumbBaseUrl(String filename) {
public static String makeThumbBaseUrl(@NonNull String filename) {
String name = new PageTitle(filename).getPrefixedText();
String sha = new String(Hex.encodeHex(DigestUtils.md5(name)));
return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name));

View file

@ -47,6 +47,9 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
}
private boolean fileExists(ContentProviderClient client, String filename) {
if (filename == null) {
return false;
}
Cursor cursor = null;
try {
cursor = client.query(BASE_URI,

View file

@ -141,8 +141,14 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
private void downloadMedia(Media m) {
String imageUrl = m.getImageUrl(),
fileName = m.getFilename();
if (imageUrl == null || fileName == null) {
return;
}
// Strip 'File:' from beginning of filename, we really shouldn't store it
fileName = fileName.replaceFirst("^File:", "");
Uri imageUri = Uri.parse(imageUrl);
DownloadManager.Request req = new DownloadManager.Request(imageUri);