Skip to content

Commit

Permalink
Closes #98, closes #99; Implement Smart Title suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Nov 16, 2021
1 parent 9e00d87 commit a98d5f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ivy.wallet.base.capitalizeWords
import com.ivy.wallet.base.isNotNullOrBlank
import com.ivy.wallet.model.entity.Transaction
import com.ivy.wallet.persistence.dao.TransactionDao
import com.ivy.wallet.ui.edit.core.SUGGESTIONS_LIMIT
import java.util.*

class SmartTitleSuggestionsLogic(
Expand Down Expand Up @@ -49,9 +50,8 @@ class SmartTitleSuggestionsLogic(
}


if (suggestions.isEmpty() && accountId != null) {
if (suggestions.size < SUGGESTIONS_LIMIT && accountId != null) {
//last resort, suggest by account

//all titles used for the specific account
//ordered by N times used

Expand All @@ -71,6 +71,8 @@ class SmartTitleSuggestionsLogic(
}

return suggestions
.filter { it != title }
.toSet()
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/edit/core/Title.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.ivy.wallet.ui.theme.components.IvyTitleTextField
import com.ivy.wallet.ui.theme.style
import java.util.*

private const val SUGGESTIONS_LIMIT = 10
const val SUGGESTIONS_LIMIT = 10

@Composable
fun ColumnScope.Title(
Expand Down Expand Up @@ -128,7 +128,7 @@ private fun PreviewTitleWithSuggestions() {
Title(
type = TransactionType.EXPENSE,
titleFocus = FocusRequester(),
initialTransactionId = UUID.randomUUID(),
initialTransactionId = null,
titleTextFieldValue = selectEndTextFieldValue(""),
setTitleTextFieldValue = {},
suggestions = setOf(
Expand Down

0 comments on commit a98d5f6

Please sign in to comment.