mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #955 from maskaravivek/fixNpe
Fixes NPE in Util function
This commit is contained in:
commit
461ca3add6
4 changed files with 13 additions and 2 deletions
|
|
@ -120,8 +120,9 @@ public class Media implements Parcelable {
|
||||||
return localUri;
|
return localUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getImageUrl() {
|
public String getImageUrl() {
|
||||||
if (imageUrl == null) {
|
if (imageUrl == null && this.getFilename() != null) {
|
||||||
imageUrl = Utils.makeThumbBaseUrl(this.getFilename());
|
imageUrl = Utils.makeThumbBaseUrl(this.getFilename());
|
||||||
}
|
}
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
|
@ -127,7 +128,7 @@ public class Utils {
|
||||||
return isoFormat.format(date);
|
return isoFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String makeThumbBaseUrl(String filename) {
|
public static String makeThumbBaseUrl(@NonNull String filename) {
|
||||||
String name = new PageTitle(filename).getPrefixedText();
|
String name = new PageTitle(filename).getPrefixedText();
|
||||||
String sha = new String(Hex.encodeHex(DigestUtils.md5(name)));
|
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));
|
return String.format("%s/%s/%s/%s", BuildConfig.IMAGE_URL_BASE, sha.substring(0, 1), sha.substring(0, 2), urlEncode(name));
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fileExists(ContentProviderClient client, String filename) {
|
private boolean fileExists(ContentProviderClient client, String filename) {
|
||||||
|
if (filename == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = client.query(BASE_URI,
|
cursor = client.query(BASE_URI,
|
||||||
|
|
|
||||||
|
|
@ -141,8 +141,14 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
|
||||||
private void downloadMedia(Media m) {
|
private void downloadMedia(Media m) {
|
||||||
String imageUrl = m.getImageUrl(),
|
String imageUrl = m.getImageUrl(),
|
||||||
fileName = m.getFilename();
|
fileName = m.getFilename();
|
||||||
|
|
||||||
|
if (imageUrl == null || fileName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Strip 'File:' from beginning of filename, we really shouldn't store it
|
// Strip 'File:' from beginning of filename, we really shouldn't store it
|
||||||
fileName = fileName.replaceFirst("^File:", "");
|
fileName = fileName.replaceFirst("^File:", "");
|
||||||
|
|
||||||
Uri imageUri = Uri.parse(imageUrl);
|
Uri imageUri = Uri.parse(imageUrl);
|
||||||
|
|
||||||
DownloadManager.Request req = new DownloadManager.Request(imageUri);
|
DownloadManager.Request req = new DownloadManager.Request(imageUri);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue