mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix preview crash on local files during upload (#1696)
* Try to get the localized version of the wikipedia article before defaulting to the English version. Tested with Spanish on physical Android device. Other notes: Difficulties building with gradle due to dexcount plugin: https://github.com/KeepSafe/dexcount-gradle-plugin/issues/234. In testing, disabled the plugin. * Update article fetch to not include unnecessary SERVICE line * Add checks for local file, check for string length
This commit is contained in:
parent
369fe3183c
commit
7b5b9169db
4 changed files with 23 additions and 5 deletions
|
|
@ -51,10 +51,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
return;
|
||||
}
|
||||
|
||||
if (thumbnailUrlCache.get(media.getFilename()) != null) {
|
||||
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
|
||||
} else {
|
||||
setImageUrl(null);
|
||||
if(media.getFilename() != null) {
|
||||
if (thumbnailUrlCache.get(media.getFilename()) != null) {
|
||||
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
|
||||
} else {
|
||||
setImageUrl(null);
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
} else { // local image
|
||||
setImageUrl(media.getLocalUri().toString());
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,11 @@ public class Utils {
|
|||
* @return string with capitalized first character
|
||||
*/
|
||||
public static String capitalize(String string) {
|
||||
return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1);
|
||||
if(string.length() > 0) {
|
||||
return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1);
|
||||
} else {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -245,6 +245,10 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
// Local files have no filename yet
|
||||
if(media.getFilename() == null) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
try {
|
||||
extractor.fetch(media.getFilename(), licenseList);
|
||||
return Boolean.TRUE;
|
||||
|
|
|
|||
|
|
@ -28,4 +28,8 @@ class UtilsTest {
|
|||
@Test fun `capitalize - pass Japanase characters`() {
|
||||
Assert.assertThat(Utils.capitalize("こんにちは"), _is("こんにちは"))
|
||||
}
|
||||
|
||||
@Test fun `capitalize does not fail on empty string`() {
|
||||
Assert.assertThat(Utils.capitalize(""), _is(""))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue