@SuppressWarnings("ConstantConditions") public static @NonNull File getFileForDocument(@NonNull Context context, @NonNull Dossier dossier,
@NonNull Document document) {
+ String documentName = document.getName() + (StringUtils.endsWithIgnoreCase(document.getName(), ".pdf") ? "" : "_visuel.pdf");
+
if (!DeviceUtils.isDebugOffline())
- return new File(FileUtils.getDirectoryForDossier(dossier), document.getName());
+ return new File(FileUtils.getDirectoryForDossier(dossier), documentName);
else
return createFileFromAsset(context, ASSET_DEMO_PDF_FILE_NAME);
}
return null;
}
+
+ /**
+ * Helper functions to query a strings end portion. The comparison is case insensitive.
+ *
+ * @param base the base string.
+ * @param end the ending text.
+ * @return true, if the string ends with the given ending text.
+ */
+ public static boolean endsWithIgnoreCase(@Nullable String base, @Nullable String end) {
+
+ // Default case
+
+ if ((base == null) || (end == null))
+ return false;
+
+ //
+
+ return (base.length() >= end.length()) && base.regionMatches(true, base.length() - end.length(), end, 0, end.length());
+ }
}