mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Parse date and title from circular string
This commit is contained in:
@@ -20,12 +20,14 @@ package net.underdesk.circolapp.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@Entity(tableName = "circulars")
|
||||
data class Circular(
|
||||
@PrimaryKey val id: Long,
|
||||
val name: String,
|
||||
val url: String,
|
||||
val date: String,
|
||||
val attachmentsNames: MutableList<String> = mutableListOf(),
|
||||
val attachmentsUrls: MutableList<String> = mutableListOf()
|
||||
) {
|
||||
@@ -33,7 +35,21 @@ data class Circular(
|
||||
fun generateFromString(string: String, url: String): Circular {
|
||||
val id = string.split(" ")[1]
|
||||
|
||||
return Circular(id.toLong(), string, url)
|
||||
val dateRegex = """(\d{2}\/\d{2}\/\d{4})"""
|
||||
val matcherDate = Pattern.compile(dateRegex).matcher(string)
|
||||
|
||||
var title = string.removeSuffix("-signed")
|
||||
|
||||
return if (matcherDate.find()) {
|
||||
title = title.removeRange(0, matcherDate.end())
|
||||
.removePrefix(" ")
|
||||
.removePrefix("_")
|
||||
.removePrefix(" ")
|
||||
|
||||
Circular(id.toLong(), title, url, matcherDate.group(1) ?: "")
|
||||
} else {
|
||||
Circular(id.toLong(), title, url, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user