feat: Build title from webDomain

This commit is contained in:
J-Jamet 2023-07-28 18:44:13 +02:00
parent b32bb609de
commit 3fdcd3c43d

View file

@ -182,10 +182,9 @@ class EntryInfo : NodeInfo {
} }
modification = true modification = true
} }
} ?: run { } ?: searchInfo.applicationId?.let { applicationId ->
// Save application id in custom field // Save application id in custom field
if (database?.allowEntryCustomFields() == true) { if (database?.allowEntryCustomFields() == true) {
searchInfo.applicationId?.let { applicationId ->
if (!containsDomainOrApplicationId(applicationId)) { if (!containsDomainOrApplicationId(applicationId)) {
addUniqueField( addUniqueField(
Field( Field(
@ -197,11 +196,26 @@ class EntryInfo : NodeInfo {
} }
} }
} }
if (title.isEmpty()) {
title = searchInfoToTitle(searchInfo)
} }
return modification return modification
} }
/**
* Capitalize and remove suffix of web domain to create a title
*/
private fun searchInfoToTitle(searchInfo: SearchInfo): String {
val webDomain = searchInfo.webDomain
return webDomain?.substring(0, webDomain.lastIndexOf('.'))?.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
} ?: searchInfo.toString()
}
fun saveRegisterInfo(database: Database?, registerInfo: RegisterInfo) { fun saveRegisterInfo(database: Database?, registerInfo: RegisterInfo) {
registerInfo.searchInfo.let {
title = searchInfoToTitle(it)
}
registerInfo.username?.let { registerInfo.username?.let {
username = it username = it
} }