Skip to content

Commit 4df09a5

Browse files
committed
Resolving codacy stuff
Signed-off-by: Leo Berman <leograntberman@gmail.com>
1 parent 66753a0 commit 4df09a5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

app/src/main/java/com/owncloud/android/ui/adapter/GalleryAdapter.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class GalleryAdapter(
6060

6161
companion object {
6262
private const val TAG = "GalleryAdapter"
63+
private const val FIRST_DAY_OF_MONTH = 1
6364
// Pattern to extract YYYY/MM or YYYY/MM/DD from file path (requires zero-padded month/day)
6465
private val FOLDER_DATE_PATTERN: Pattern = Pattern.compile("/(\\d{4})/(\\d{2})(?:/(\\d{2}))?/")
6566

@@ -69,13 +70,15 @@ class GalleryAdapter(
6970
*/
7071
@VisibleForTesting
7172
fun extractFolderDate(path: String?): Long? {
72-
if (path == null) return null
73-
val matcher = FOLDER_DATE_PATTERN.matcher(path)
74-
if (matcher.find()) {
75-
val year = matcher.group(1)?.toIntOrNull() ?: return null
76-
val month = matcher.group(2)?.toIntOrNull() ?: return null
77-
val day = matcher.group(3)?.toIntOrNull() ?: 1
78-
return Calendar.getInstance().apply {
73+
val matcher = path?.let { FOLDER_DATE_PATTERN.matcher(it) } ?: return null
74+
if (!matcher.find()) return null
75+
76+
val year = matcher.group(1)?.toIntOrNull()
77+
val month = matcher.group(2)?.toIntOrNull()
78+
val day = matcher.group(3)?.toIntOrNull() ?: FIRST_DAY_OF_MONTH
79+
80+
return if (year != null && month != null) {
81+
Calendar.getInstance().apply {
7982
set(Calendar.YEAR, year)
8083
set(Calendar.MONTH, month - 1)
8184
set(Calendar.DAY_OF_MONTH, day)
@@ -84,8 +87,9 @@ class GalleryAdapter(
8487
set(Calendar.SECOND, 0)
8588
set(Calendar.MILLISECOND, 0)
8689
}.timeInMillis
90+
} else {
91+
null
8792
}
88-
return null
8993
}
9094
}
9195

0 commit comments

Comments
 (0)